Python Forum

Full Version: [split] Save logs to server
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Please Help !! How can i save logs in the server from the client to get what the client tries to do ??

Client.py

!/usr/bin/python
import socket
def Main ():
client_socket = socket.socket()
server_name = '192.168.137.170'
server_port = 555
client_socket.connect ((server_name,server_port))
data = client_socket.recv(1024)
print 'Server is : ' ,data
client_socket.send("GET /admin/wp-admin.php http/1.1")
pagedata = client_socket.recv(1024)
print 'Web page : ' ,pagedata
client_socket.close()
if name== 'main' : Main ()
----------------------------------


Server.py

#!/usr/bin/python

import socket

def Main () :  
server_name = ''
server_port = 555
server_banner = """Sagem F@st 2604 ADSL router linux 7 3.49a4G_Topnet

| banner: \xFF\xFD\x01\xFF\xFD!\xFF\xFB\x01\xFF\xFB\x03FAST2604 ADSL Rout

|_er (Software Version:3.49a4G_Topnet)\x0D\x0ALogin:

Service Info: Device: broadband router """





      

fakepage = """ 

<HTML><HEAD><TITLE>401 Unauthorized</TITLE></HEAD>

<BODY BGCOLOR="#cc9999"><H4>401 Unauthorized</H4>

Authorization required.



</BODY></HTML>

        """
server_socket = socket.socket()
server_socket.bind((server_name, server_port))
server_socket.listen(10)
print "server ON"
 while True : 
 c,addr = server_socket.accept()

 print "We have connection from client ip" ,addr       

 data = c.recv(1024)
       # data = "GET /admin/wp-admin.php http/1.1"
       # Parse data and get URI= /admin/wp-admin.php
 print "Bad guy is looking for: " ,data 
       # change data with parsed data
 print "sending fake page : " ,fakepage
 c.send (fakepage)
 c.close()

if __name__== '__main__' :
Main()

i'm really sorry but please can you help me
Your post is truly a mess. After reading the docs on how to properly post a question, please re-post your code between the code tags without any formatting.  Remember in Python to use 'spaces' not 'tabs' for indentation, the recommended amount being 4 spaces for each indented level.  If you received any error messages, make sure you include the entire error message between the error tags.
Quote:
#!/usr/bin/python
import socket
def Main () :    
   server_name = ''    
   server_port = 555
   server_banner = """Sagem F@st 2604 ADSL router linux 7 3.49a4G_Topnet
   | banner: \xFF\xFD\x01\xFF\xFD!\xFF\xFB\x01\xFF\xFB\x03FAST2604 ADSL Rout
   |_er (Software Version:3.49a4G_Topnet)\x0D\x0ALogin:
   Service Info: Device: broadband router """      
   fakepage = """ 
   <HTML><HEAD><TITLE>401 Unauthorized</TITLE></HEAD>
   <BODY BGCOLOR="#cc9999"><H4>401 Unauthorized</H4>
   Authorization required.
   <HR>
   <ADDRESS><A HREF="http://www.acme.com/software/micro_httpd/">micro_httpd</A></A></ADDRESS>
   </BODY></HTML>
         """     
    server_socket = socket.socket()     
    server_socket.bind((server_name, server_port)     
    server_socket.listen(10)    
    print "server ON"
    while True : 
         c,addr = server_socket.accept()
    print "We have connection from client ip" ,addr       
    data = c.recv(1024)
   # data = "GET /admin/wp-admin.php http/1.1"
   # Parse data and get URI= /admin/wp-admin.php      
   print "Bad guy is looking for: " ,data 
   # change data with parsed data
   print "sending fake page : " ,fakepage        
   c.send (fakepage)
   c.close()
if __name__== '__main__' :
    Main()

Quote:
#!/usr/bin/python
import socket 
def Main ():  
   client_socket = socket.socket()
   server_name = '192.168.137.170'
   server_port = 555
   client_socket.connect ((server_name,server_port))
   data = client_socket.recv(1024)
   print 'Server is : ' ,data
   client_socket.send("GET /admin/wp-admin.php http/1.1")
   pagedata = client_socket.recv(1024)
   print 'Web page : ' ,pagedata
   client_socket.close()
if __name__== '__main__' :     
    Main ()

Sir, i'm really sorry about this misunderstanding. Well, im trying to make a Honeypot to detect what the client is trying to search or to write in the server. So i've made a connection between a server and a client and now i'm really stack. I don't know how to get logs and save them in a file. for example if the a client want to connect to the server and he writes wrong login and password the i will find those information that he writes them in log_file.txt. Thank you sir
As you did it you have to implement the HTTP protocol yourself (and a quite complete protocol if you want to catch more than th emost trivial attacks).


A much better solution would be to use a server framework (there are two popular Python-based frameworks for servers: Flask and Django) to which you add you own code in the proper hooks.