🐝
OSCP 2022 Materials
  • General
    • Whoami
    • Resources
    • Frequently Asked Questions
    • Shared Resource
  • Enumeration
    • Foreword
    • FTP
    • SMTP
    • DNS
    • Finger
    • HTTP/ HTTPS
      • Login Attacks
        • PHP Logins
      • XSS
      • LFI ( LFI -> RCE )
      • RFI ( RFI -> RCE )
      • CMS Exploitation
        • Wordpress
        • Magento
        • Bludit
        • Tomcat
        • Drupal
      • PHPMyAdmin
    • Kerberos
    • POP3
    • SMB
    • IMAP
    • SNMP
    • IRC
    • RSync
    • MSSQL
    • NFS
    • REDIS
    • Port Forwarding
  • Linux Post Exploitation
    • Post Exploit Checks
    • Pivoting ( ProxyChains )
  • Windows Post Exploitation
    • Post Exploit Checks
    • Active Directory ( Recon -> PE)
    • Notes
      • Powershell
      • Commands
  • Buffer Overflow
    • Hackthebox
    • TryHackMe
  • Mobile Pentesting
    • Android Pentesting
      • Lab TroubleShoot
      • Root Detection Bypass ( Manual )
      • Physical Device
  • MISC
    • Useful
    • Web
    • Linux
    • Application Specific
    • Programming Notes for Offensive Security
      • Python
    • Forensics
      • Disk Forensics
    • Inspection
    • Troubleshooting
      • Mouse Flickering
Powered by GitBook
On this page
  • Misc
  • Requests

Was this helpful?

  1. MISC
  2. Programming Notes for Offensive Security

Python

Python modules and usage tips that I use often

Misc

  • Get a dynamically updated print output

for i in range(182930):
    print(f"\rNow the value is{i}", flush=False, end="")
  • Running a python script with -i flag brings us to the end of the exectuion and prompts a python shell

pyhton3 -i exploit.py
  • To inspect what are the supported methods available from the output object the dir can be used

resp = requests.get("https://dhaneshsivasamy07.gitbook.io")

# look at the supported attributes
dir(resp)
# access the method
resp.text 
resp.elapsed
resp.status_code
# can be further inspected
dir(resp.text)
dir(resp.elapsed)
# accessing
resp.elapsed.microseconds
resp.elapsed.total_seconds()

Requests

  • Requests module are used to make requests to the webpage

import requests
url = "https://google.com"

# make a get request
r = requests.get(url=url)
# know the status code
print(r.status_code)
# print the contents of the respone
print(r.text)

# make a post request
p = requests.post(url=url)
# status code and contents can be accessed with p.status_code and p.text

# send a data along with the post request
data = {"user" : "dnoscp", "password" : "iamfastasfuckboii"}
url = "http://127.0.0.1/login.php"
dn = requests.post(url=url, data=data)

# make the requst go through a proxy
data = {"user" : "dnoscp", "password" : "iamfastasfuckboii"}
url = "http://127.0.0.1/login.php"
proxy = {"http" : "http://127.0.0.1:8080"}
dnp = requests.post(url=url, data=data, proxies=proxy)

# When handling with forms and ajax requests, make use of the Session() which hold
# the information that is processed and will use in the subsequent request
# Session() is a function in requests module
session = Session()
get_ = session.get(url=url)
post_ = session.post(url=url, data=data, proxies=proxy)

PreviousProgramming Notes for Offensive SecurityNextForensics

Last updated 2 years ago

Was this helpful?