66
JOSE MANUEL ORTEGA @JMORTEGAC Ethical hacking with Python tools

PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

  • Upload
    lehuong

  • View
    228

  • Download
    2

Embed Size (px)

Citation preview

Page 1: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

JOSE MANUEL ORTEGA

@JMORTEGAC

Ethical hacking with

Python tools

Page 2: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

https://speakerdeck.com/jmortega

Page 3: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

INDEX

Introduction Python pentesting

Modules(Sockets,Requests,BeautifulSoup,Shodan)

Analysis metadata

Port scanning & Checking vulnerabilities

Advanced tools

Pentesting-tool

Page 4: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

Python Pentesting

Multi platform

Prototypes and proofs of concept(POC)

Many tools and libraries focused on security

OSINT and Pentesting tools

Very good documentation

Page 5: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

Python Pentesting

Page 6: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

http://sparta.secforce.com/

Page 7: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

The Harvester

Page 8: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

The Harvester

Page 9: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

W3AF

Page 10: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

Tools

Scapy Capturing and analysing network packets

FiMap Detecting RFI/LFI vulnerabilites

XSScrapy Detecting XSS vulnerabilites

Page 11: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

Sockets Port scan

import socket #TCP sock = socket(socket.AF_INET,socket.SOCK_STREAM)

result = sock.connect_ex(('127.0.0.1',80)) if result == 0: print "Port is open" else: print "Port is filtered"

Page 12: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

Sockets Port scan

Page 13: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

Socket resolving IP/domain

Page 14: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

Banner server

Page 15: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

Banner server

Page 16: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

Requests

Page 17: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

Checking headers

Page 18: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

Checking headers

Page 19: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

Requests

import requests http_proxy = "http://10.10.10.10:3000" https_proxy = "https://10.10.10.10:3000" proxyDict = { "http" : http_proxy, "https" : https_proxy }

r = requests.get(url,proxies=proxyDict)

Page 20: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

Requests Authentication

Page 21: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

BeautifulSoup

Page 22: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

Internal/external links

Page 23: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

Internal/external links

Page 24: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

Extract images and documents

Page 25: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

Scrapy

Page 26: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

Web Scraping

Page 27: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

Shodan

Page 28: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

https://developer.shodan.io

Page 29: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

Shodan

import shodan SHODAN_API_KEY = "insert your API key here" api = shodan.Shodan(SHODAN_API_KEY)

Page 30: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

Shodan

Page 31: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

https://www.shodan.io/host/136.243.32.71

Page 32: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

Shodan

Page 33: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

Shodan

Page 34: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

BuiltWith

pip install builtwith

builtwith.parse(‘https://ep2016.europython.eu’)

Page 35: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

Analysis metadata

Page 36: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

Analysis metadata

Page 37: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

Analysis metadata

Page 38: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

Port Scanning

Page 39: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

Python-nmap

Automating port scanning

Synchronous and asynchronous modes

import nmap # Synchronous nm = nmap.PortScanner() # nm.scan(‘ip/range’,’port_list’) results = nm.scan('127.0.0.1', '22,25,80,443')

Page 40: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

NmapScanner

Page 41: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

NmapScanner

for port in port_list: NmapScanner().nmapScan(ip, port)

Page 42: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

NmapScanner Async

#Asynchronous nm_async = nmap.PortScannerAsync() def callback_result(host, scan_result): print '------------------' print host, scan_result nm_async.scan(hosts='192.168.1.0/30', arguments='-sP', callback=callback_result) while nm_async .still_scanning(): print("Waiting >>>") nm_async.wait(2)

Page 43: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

NmapScanner Async

Page 44: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

Scripts Nmap

Page 45: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

Scripts Nmap

Programming routines allow to find potential vulnerabilities in a given target

First check if the port is open

Detect vulnerabilities in the service port openned

nm.scan(arguments="-n -A -p3306 --script=/usr/share/nmap/scripts/mysql-info.nse")

Page 46: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

Mysql Scripts Nmap

Page 47: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

Check FTP Login Anonymous

Page 48: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

Check FTP Login Anonymous

Page 49: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

Check Webs sites

pip install pywebfuzz

https://github.com/disassembler/pywebfuzz

Page 50: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

PyWebFuzz

from pywebfuzz import fuzzdb import requests logins = fuzzdb.Discovery.PredictableRes.Logins domain = "http://192.168.56.101" for login in logins: print “Checking... "+ domain + login response = requests.get(domain + login) if response.status_code == 200: print "Login Resource: " +login

Page 51: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

PyWebFuzz

Page 53: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

Heartbleed

Page 54: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

Heartbleed

Page 55: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

Advanced tools

Page 56: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

Metasploit

python-msfrpc

Page 57: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

Metasploit API call

Calls in msgpack format

Page 58: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

Nexpose

Tool developed by Rapid7 for scanning and vulnerability discovery.

It allows programmatic access to other programs via HTTP/s requests.

BeautifulSoup to obtain data from vulnerabilities server

Page 59: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

Nexpose

Page 60: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

Pentesting tool

Page 61: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

https://github.com/jmortega/python-pentesting

Page 62: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

https://github.com/jmortega/europython_ethical_hacking

Page 63: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

References & libs

http://docs.shodanhq.com

http://docs.python-requests.org/en/master/

http://scrapy.org

http://xael.org/pages/python-nmap-en.html

http://www.pythonsecurity.org/libs

https://github.com/dloss/python-pentest-tools

http://kali-linux.co/2016/07/12/python-tools-for-penetration-testers%E2%80%8B/

https://github.com/PacktPublishing/Effective-Python-Penetration-Testing

Page 64: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

Books

Page 65: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

Books

Page 66: PenTest using Python · PDF filePython Pentesting Multi platform Prototypes and proofs of concept(POC) Many tools and libraries focused on security OSINT and Pentesting tools

THANK YOU!