forked from OpenFireTechnologies/Socket-Server-Client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
116 lines (99 loc) · 4.3 KB
/
client.py
File metadata and controls
116 lines (99 loc) · 4.3 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#-------------------------------------------------------------------------------
# Name: Client.py
# Purpose: Client to connect to server
#
# Author: Shubham Raj (http://www.facebook.com/xceptioncode)
#
# Website: http://www.openfire-security.net
# Forum: http://forum.openfire-security.net
#
# Created: 03/09/2013
# Last_Update: 01/12/2014
# Copyright: (c) Xception 2013
# Licence: Open Source
#-------------------------------------------------------------------------------
import socket, sys, subprocess, os
#from threading import Timer
if sys.platform == 'linux-i386' or sys.platform == 'linux2' or sys.platform == 'darwin':
SysClS = 'clear'
elif sys.platform == 'win32' or sys.platform == 'dos' or sys.platform[0:5] == 'ms-dos':
SysCls = 'cls'
else:
SysCls = 'unknown'
os.system(SysCls)
print "\n\n"
print "\t\t________ ___________.__"
print "\t\t\_____ \ ______ ____ ____ \_ _____/|__|______ ____ "
print "\t\t / | \\____ \_/ __ \ / \ | __) | \_ __ \_/ __ \ "
print "\t\t/ | \ |_> > ___/| | \| \ | || | \/\ ___/ "
print "\t\t\_______ / __/ \___ >___| /\___ / |__||__| \___ >"
print "\t\t \/|__| \/ \/ \/ \/"
print "\t\t Socket Client\n\n"
def help():
print "\n[#] USAGE: client.py IP PORT"
print "[#] EX: client.py 111.111.1.11 8000\n"
print "[+] This is client socket"
print "[+] Client can easily connect to server and start chatting with server,\n[+] Client can also send commands to server to get executed & vice versa"
print "[+] To send commands to server : "
print "[+] command : command_to_execute"
print "[+] like - command : ipconfig"
print "[=] NOTE : All the cmd commands may not execute currently."
exit()
try:
ip = sys.argv[1]
port = sys.argv[2]
except IndexError:
print "[=] Not enough arguments!"
help()
def conversation():
while True:
try:
data = raw_input("Enter text to send to server : ")
if ("%s" % data):
sock.send("%s" % data)
except KeyboardInterrupt:
print "CTRL^C Pressed, Shutting client"
sock.close()
sys.exit()
while True:
data_recv = sock.recv(104448)
if not data_recv:
print "[=] Connection closed by remote host"
break
elif data_recv[:10] == 'command : ':
print "\n[+] Server sent a command to execute. Command : %s" % data_recv[10:]
try:
if sys.platform == 'linux-i386' or sys.platform == 'linux2' or sys.platform == 'darwin':
new_data = subprocess.Popen(["/bin/sh", '-c', data_recv[10:]],stdout=subprocess.PIPE).communicate()[0]
sock.send("\n %s " % new_data)
print "\nSent Command response to server"
continue
elif sys.platform == 'win32' or sys.platform == 'dos' or sys.platform[0:5] == 'ms-dos':
new_data = subprocess.Popen(data_recv[10:],stdout=subprocess.PIPE, shell=True).communicate()[0]
sock.send("\n %s " % new_data)
print "\nSent Command response to server"
continue
else:
print "\n[=] System plattform not detected to execute commands."
sock.send("Sorry, remote server system plattform not detected to execute commands.")
continue
except Exception as e:
sock.send("Seems you sent a wrong command to get executed, Error occured!", e)
continue
else:
print "\n[+] Server Sent : %s\n" % data_recv
break
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((ip, int(port)))
print "[+] Connected with server, IP : %s & PORT : %d \n" % (ip, int(port))
#t = Timer(0.01, conversation())
#t.start()
conversation()
sock.close()
except KeyboardInterrupt:
print "CTRL^C Pressed, Shutting client"
sys.exit()
except Exception as e:
print "Error occured"
print "Error => %s" % e