Python Forum
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[split] Save logs to server
#1
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
Reply
#2
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.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#3
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
Reply
#4
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.
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  time difference bettwenn logs enkliy 14 875 Nov-21-2023, 04:51 PM
Last Post: rob101
  how to save to multiple locations during save cubangt 1 509 Oct-23-2023, 10:16 PM
Last Post: deanhystad
  Bot refuses to count logs. M1racle 0 1,231 Dec-13-2021, 06:42 PM
Last Post: M1racle
  How to take the tar backup files form remote server to local server sivareddy 0 1,871 Jul-14-2021, 01:32 PM
Last Post: sivareddy
  Get Azure activity logs using python script raham3406 4 3,514 Apr-27-2021, 05:10 AM
Last Post: raham3406
  How to save Python Requests data sent to server? RedLeonard 5 4,799 Jul-05-2020, 10:33 AM
Last Post: RedLeonard
  python realtime parsing logs anna 2 2,747 Jul-05-2020, 06:36 AM
Last Post: anna
  Save Arduino data in mysql server via raspberrypi rithikvg 1 3,348 Jun-24-2020, 10:59 PM
Last Post: Larz60+
  capture logs on specific port anna 1 1,727 Jun-27-2019, 03:47 PM
Last Post: Larz60+
  Collect logs for a function in python using shell script viru 1 3,752 Aug-28-2017, 07:54 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020