You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

81 lines
2.3 KiB

import re
import subprocess
import tempfile
import os
import pexpect
import struct
import sys
import mysql.connector
import requests
def do_worker(str_instruction):
try:
# 使用 subprocess 执行 shell 命令
result = subprocess.run(str_instruction, shell=True, text=True,capture_output=True)
return {
"returncode": result.returncode,
"stdout": result.stdout,
"stderr": result.stderr
}
except Exception as e:
return {"error": str(e)}
def do_worker_ftp_pexpect(str_instruction):
# 解析指令
lines = str_instruction.strip().split('\n')
cmd_line = lines[0].split('<<')[0].strip() # 提取 "ftp -n 192.168.204.137"
inputs = [line.strip() for line in lines[1:] if line.strip() != 'EOF']
# 使用 pexpect 执行命令
child = pexpect.spawn(cmd_line)
for input_line in inputs:
child.expect('.*') # 等待任意提示
child.sendline(input_line) # 发送输入
child.expect(pexpect.EOF) # 等待命令结束
output = child.before.decode() # 获取输出
child.close()
return output
def do_worker_ftp_script(str_instruction):
# 创建临时文件保存输出
with tempfile.NamedTemporaryFile(delete=False) as tmpfile:
output_file = tmpfile.name
# 构建并执行 script 命令
script_cmd = f"script -c '{str_instruction}' {output_file}"
result = subprocess.run(script_cmd, shell=True, text=True)
# 读取输出文件内容
with open(output_file, 'r') as f:
output = f.read()
# 删除临时文件
os.remove(output_file)
return output
import socket
import ssl
def dynamic_fun():
try:
host = "58.216.217.70"
port = 992
# Create a socket and wrap it with SSL context since service is SSL/Telnet
context = ssl.create_default_context()
sock = socket.create_connection((host, port), timeout=5)
ssl_sock = context.wrap_socket(sock, server_hostname=host)
# Attempt to receive banner
banner = ssl_sock.recv(1024)
ssl_sock.close()
return (True, banner.decode("utf-8", errors="ignore"))
except Exception as e:
return (False, str(e))
if __name__ == "__main__":
# 示例使用
bok,res = dynamic_fun()
print(bok,res)