首先,我很抱歉,因为我不知道怎么问我的问题,上次在一个安全挑战中,我试图用curl发送一些请求,在他们进行了大量测试以了解挑战是如何工作的几分钟之后,我尝试编写一些python代码来自动生成我的请求,并赢得了一些时间
以下是我曾经尝试过的一些请求: 最基本的
curl http://10.20.0.50:80/
然后我必须指定路径示例:
curl http://10.20.0.50:80/transfert/solde
curl http://10.20.0.50:80/account/creat
...
有时添加授权或cookie。。。你知道吗
curl http://10.20.0.50:80/transfert/solde -H "Authorization:Basic bXlhcGk6U3VwZXJTZWNyZXRQYXMkdzByZA==" -H "cookie: PHPSESSID=23c3jc3spuh27cru38kf9l2au5;"
或添加一些参数:
curl http://10.20.0.50:80/transfert/solde -H "Authorization:Basic bXlhcGk6U3VwZXJTZWNyZXRQYXMkdzByZA==" -H "cookie: PHPSESSID=23c3jc3spuh27cru38kf9l2au5;" --data-raw '{"id":"521776"}' -v
所以问题是,我必须测试很多东西,有没有授权,有没有cookie,更改cookie几次,添加--原始数据。。。我试着写一个剧本来帮我做这个,但很难看:
url = "http://10.20.0.50:80/"
auth = ' -H "Authorization:Basic bXlhcGk6U3VwZXJTZWNyZXRQYXMkdzByZA=="'
def generate(path,c=None,h=True,plus = None):
#c cookie , h if we put authentification
#plus add more code at the end of the request
global auth # authentification
global url
if c:
cook = ' -H "cookie: PHPSESSID={};"'.format(c)
req = "curl "+url+path
if h:#h bool
req += auth
if c :
req += cook
if plus :
req += plus
req+=" -v "
return req
为了可读性,我去掉了一个参数——数据行,我想知道是否有更好的方法!不仅仅是这个例子,一般来说,如果我想创建python代码,生成类的代码源,我必须指定类的名称,属性和类型,代码生成一个模板。。。你知道吗
我希望你能帮助我 PS:如果我犯了一些错误,我的英语很抱歉
或许,一种“改进”代码的方法是这样做:
输出:
相关问题 更多 >
编程相关推荐