MatejKovacic/silent-sms-ping

Sending data to threat analytics server

Opened this issue · 1 comments

Example of Python3 server receiving data through HTTP post JSON call. Server is listening on port 3000 on /api/data, and storing data to dile data.json.

# Import the necessary modules
import json
from http.server import BaseHTTPRequestHandler, HTTPServer

# Define the HTTP request handler
class RequestHandler(BaseHTTPRequestHandler):
    def do_POST(self):
        # Set the response headers
        self.send_response(200)
        self.send_header('Content-Type', 'application/json')
        self.send_header('Access-Control-Allow-Origin', '*')
        self.end_headers()
        
        # Handle only POST requests to the '/api/data' endpoint
        if self.path == '/api/data':
            # Read the request data
            content_length = int(self.headers['Content-Length'])
            body = self.rfile.read(content_length)
            
            # Parse the JSON data and save it to a file
            try:
                data = json.loads(body)
                with open('data.json', 'a') as f:
                    f.write(json.dumps(data) + '\n')
                self.wfile.write(json.dumps({'success': True}).encode())
            except ValueError:
                self.send_error(400, 'Invalid JSON data')
        else:
            self.send_error(404, 'Endpoint not found')

# Create the HTTP server
server_address = ('', 3000)
httpd = HTTPServer(server_address, RequestHandler)

# Start the HTTP server
print('Server listening on port 3000')
httpd.serve_forever()

Example of curl call to the server:

curl -X POST -H "Content-Type: application/json" -d '{"PDUtype": "SMS-DELIVER", "datetime": "2023-03-21T13:28:06.419Z", "toNumber": "+386 41 123 456"}' http://localhost:3000/api/data

Content of a JSON file (cat data.json):

{"PDUtype": "SMS-DELIVER", "datetime": "2023-03-21T13:28:06.419Z", "toNumber": "+386 41 123 456"}
{"PDUtype": "SMS-DELIVER", "datetime": "2023-03-22T08:30:12.528Z", "toNumber": "+386 41 123 456"}

(This is just quick mockup.)

Example of JSON data structure:

{
  "pdu_type": "SMS-DELIVER",
  "local_date_time": "3/24/2023 18:28:20 GMT+3",
  "utc_date_time": "3/24/2023 16:28:20 UTC",
  "to_number": "+386 41 123 456",
  "smsc": "+386 11 000 111",
  "from_number": "+386 30 789 321",
  "from_display": "+38630789321",
  "from_port": 0,
  "to_port": 37273,
  "msg": "846853",
  "payload": "087...033",
  "data_hex": "003...300",
  "user_location": {
    "longitude": null,
    "latitude": null
  },
  "unique_device_id": null,
  "sent_to_server": null,
  "all_info_data_field": null,
  "technical_data": {
    "country": null,
    "operator": null,
    "brand": null,
    "mcc": null,
    "mnc": null,
    "lac": null,
    "cid": null,
    "arfcn": null,
    "bsic": null,
    "psc": null,
    "pci": null,
    "location": {
      "longitude": null,
      "latitude": null
    },
    "signal_level": {
      "asu": null,
      "integer": null,
      "dbm": null
    },
    "signal_type": null
  }
}