Python Pentesting Cheat Sheet

0% found this document useful (0 votes)
110 views1 page
This document provides a Python cheat sheet for penetration testing. It includes examples of common port scanning and reconnaissance techniques like GET requests, header retrieval, cookie ca…

Uploaded by

meiolouco4758
  • About LIFARS
  • Common Ports Reference
  • Python Pentest Cheat Sheet

Python Pentest Cheat Sheet Common Ports Reference

Simple GET request for html source host> -p <target port>')


parser.add_option('-H', dest='tgtHost',
import httplib
type='string',\
connection = help='specify target host')
[Link]("xyz_website.com") parser.add_option('-p', dest='tgtPort',
[Link]("GET", "/[Link]") type='string',\
response = [Link]() help='specify target port[s]
relevant_payload = [Link]() separated by comma')
print(relevant_payload) (options, args) = parser.parse_args()
tgtHost = [Link]
2Get http response headers tgtPorts = str([Link]).split(',')
import urllib2 if (tgtHost == None) | (tgtPorts[0] == None):
url = '[Link] print [Link]
headers = { 'User-Agent' : 'Mozilla/5.0 (Windows NT exit(0)
6.3; WOW64)' } for tgtPort in tgtPorts:
nmapScan(tgtHost, tgtPort)
request = [Link](url, None, headers) if __name__ == '__main__':
response = [Link](request) main()
headers = [Link]
print(headers)
Capture cookies generation/possibly session IDs Site recon – scraping links from target
from anonBrowser import * from anonBrowser import *
#import anonBrowser from BeautifulSoup import BeautifulSoup
import os
import optparse
ab = anonBrowser(proxies=[],\ import re
user_agents=[('User-agent','My browser')]) def printLinks(url):
ab = anonBrowser()
for attempt in range(1, 10 ): [Link]()
[Link]() page = [Link](url)
print '[*] Fetching page' html = [Link]()
response = [Link]('[Link] try:
print '[+] Printing Links From Regex.'
for cookie in ab.cookie_jar: link_finder = [Link]('href="(.*?)"')
print cookieprint(headers) links = link_finder.findall(html)
Testing for anonymous FTP login for link in links:
import ftplib print link
def testAnonymousLogin(hostname): except:
pass
try: try:
ftp = [Link](hostname) print '\n[+] Printing Links From BeautifulSoup.'
[Link]('anonymous', 'xyz@[Link]') soup = BeautifulSoup(html)
print '\n[*] ' + str(hostname) +\ links = [Link](name='a')
' FTP Anonymous Logon Succeeded.' for link in links:
[Link]() if link.has_key('href'):
return True print link['href']
except:
except Exception, e: pas
print '\n[-] ' + str(hostname) +\ def main():
' FTP Anonymous Logon Failed!' parser = [Link]('usage %prog ' +\
return False '-u <target url including protocol>')
host = 'xyz_website.com' parser.add_option('-u', dest='tgtURL', PDF version is available at [Link]
testAnonymousLogin(host) type='string',\
help='specify target url') LIFARS is a digital forensics and cybersecurity intelligence firm based in
Nmap scan using python (options, args) = parser.parse_args() New York City. Our incident response and penetration testing teams
import nmap url = [Link] consist of the top experts in the field. As a testament to our excellence,
import optparse if url == None:
def nmapScan(tgtHost,tgtPort): LIFARS was ranked the #2 cybersecurity company in New York Metro
print [Link]
nmScan = [Link]() exit(0)
area on the Cybersecurity 500 list of the hottest and most innovative
[Link](tgtHost,tgtPort) else: cyber security companies.
state=nmScan[tgtHost]['tcp'][int(tgtPort)]['state'] printLinks(url) WARNING: Only scan hosts and networks
print "[*] " + tgtHost + " tcp/"+tgtPort +" "+state if __name__ == '__main__': that you own or have permission to scan!
def main(): main() Don’t be evil. LIFARS LLC is not responsible
parser = [Link]('usage %prog '+\ for misuse of information provided in this
'-H <target
document.

Python Pentest Cheat Sheet 
Common Ports Reference 
 Simple GET request for html source 
import httplib 
connection = 
ht

You might also like