Skip to content

Instantly share code, notes, and snippets.

@ak4zh
Created April 26, 2017 08:50
Show Gist options
  • Save ak4zh/e6ae46be1948497887aed4d32ca34688 to your computer and use it in GitHub Desktop.
Save ak4zh/e6ae46be1948497887aed4d32ca34688 to your computer and use it in GitHub Desktop.
get_payload.py
import requests
from bs4 import BeautifulSoup
import re
import clipboard
clipboard = clipboard.get()
if 'http' not in clipboard:
url = input('Enter the URL: ') #Enter the url address of website you want to generate payload template for
else:
url = (re.search('(http\S+)', clipboard)).group(1)
payload = {} #Enpty dictionary created
r = requests.post(url) #url request to get website contents
soup = BeautifulSoup(r.content, 'html5lib')
#look for all form fields using regex
list = re.findall('<input.+?>', str(soup))
#check form method POST or GET
method = (re.search('method="(.+?)"', str(soup))).group(1)
#loop for each form fields
for input in list:
name = (re.search('name="(.+?)"', str(input))).group(1)
value = (re.search('value="(.+?)"', str(input))).group(1)
if 'Clear' not in value: #to remove clear buttons from form
payload[name] = value
#print and format output
print('import requests')
print('from bs4 import BeautifulSoup\n')
print("url = '" + url + "'\n")
print('payload = ', end='')
print(payload)
print('\n\n')
print("r = requests." + method + "(url)")
print("soup = BeautifulSoup(r.content, 'html5lib')")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment