Skip to content

Instantly share code, notes, and snippets.

@Resousse
Created November 3, 2020 06:59
Show Gist options
  • Save Resousse/624f5b34c94bdc4c216655438c8262ff to your computer and use it in GitHub Desktop.
Save Resousse/624f5b34c94bdc4c216655438c8262ff to your computer and use it in GitHub Desktop.
Get Messages data related to a domain from signal-spam.fr
# -*- coding: utf-8 -*-
import time
import sys
import requests
import json
import re
from decouple import config
import urllib.parse
import pyperclip
# Sometimes I receive spam from AWS SES, that I record on signal-spam.fr
# but at the end of each month I send the email headers + data of all email related to this domain to email-abuse@amazon.com and ec2-abuse@amazon.com
# This script needs a .env file (python-decouple) with user=yoursignalspamuser and password=yourpassword, then line 64, the domain must be adapted to yours.
# All the header + data will be retrieved from signal-spam and will be copied in the copyclip (pyperclip), then you just have to prepare a mail to AWS (or other web service provider) and paste it
def connect(s, user, password):
s.get('https://signalants.signal-spam.fr/')
token = s.get('https://signalants.signal-spam.fr/login')
m = re.search('<input type="hidden" name="authenticity_token" value="([^"]+)"', token.text)
if m:
headers = {'Content-Type': "application/x-www-form-urlencoded"}
time.sleep(8)
payload = "utf8=✓&authenticity_token={}&user[email_or_login]={}&user[password]={}&user[remember_me]=0&button=".format(m.group(1), user, password)
cookie = s.post('https://signalants.signal-spam.fr/login', headers = headers, allow_redirects = True, data=payload.encode('utf-8'))
if cookie.status_code == 302 or "Mon activité" in cookie.text:
time.sleep(1)
req = s.get('https://signalants.signal-spam.fr/', headers = {'Connection': 'keep-alive', 'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate, br'}, allow_redirects = False)
time.sleep(1)
return "OK"
print ("unable to connect")
return None
def getPage(s, domain, page = 1):
req = s.get("https://signalants.signal-spam.fr/reportings?page={}".format(page))
fa = re.findall('<tr><td class="checkbox-table">.*?&lt;(.*?)&gt;</td><td>.*?href="(/reportings/\d+)">Détail</a></td></tr>', req.text)
lst = []
if fa:
for f in fa:
if domain in f[0]:
lst.append(getHeader(s, f[1]))
else:
return None
return lst
def getHeader(s, url):
content = s.get('https://signalants.signal-spam.fr'+url)
m = re.search('<pre class="message">(.+)</pre>', content.text, re.M | re.S )
if m:
return m.group(1)
return None
user = config('User', default='no')
password = config('Password', default='no')
s = requests.Session()
s.headers['User-Agent'] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.80 Safari/537.36"
if connect(s, user,password) == 'OK':
i = 1
cp = ""
while True:
lst = getPage(s, 'booklet-elites.online', i)
if lst is None:
break
for l in lst:
cp += l + '\n\n=================================================================\n\n'
i += 1
pyperclip.copy(cp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment