Lucas Teske gist felülvizsgálása 6 years ago. Revízióhoz ugrás
2 files changed, 127 insertions
sms_broadcast.py(fájl létrehozva)
| @@ -0,0 +1,66 @@ | |||
| 1 | + | #!/usr/bin/env python | |
| 2 | + | import telnetlib | |
| 3 | + | import sqlite3 | |
| 4 | + | import sys | |
| 5 | + | ||
| 6 | + | imsi = 999999999999999 | |
| 7 | + | HLR_DATABASE = "configs/hlr.sqlite3" | |
| 8 | + | ||
| 9 | + | def check_extension(extension): | |
| 10 | + | conn.write(b"show subscriber extension %s\n" % extension) | |
| 11 | + | res = conn.read_until(b"OpenBSC> ") | |
| 12 | + | ||
| 13 | + | if b"No subscriber found for extension" in res: | |
| 14 | + | create_subscriber(extension) | |
| 15 | + | ||
| 16 | + | def create_subscriber(extension): | |
| 17 | + | print("No user with excension %s found. Creating new..." % extension) | |
| 18 | + | print("Extension: %s, IMSI: %d" % (extension, imsi)) | |
| 19 | + | ||
| 20 | + | conn.write(b"show subscriber imsi %d\n" % imsi) | |
| 21 | + | res = conn.read_until(b"OpenBSC> ") | |
| 22 | + | ||
| 23 | + | if b"No subscriber found for imsi" in res: | |
| 24 | + | conn.write(b"subscriber create imsi %d\n" % imsi) | |
| 25 | + | conn.read_until(b"OpenBSC> ") | |
| 26 | + | ||
| 27 | + | conn.write(b"enable\n") | |
| 28 | + | conn.read_until(b"OpenBSC# ") | |
| 29 | + | conn.write(b"subscriber imsi %d extension %s\n" % (imsi, extension)) | |
| 30 | + | conn.read_until(b"OpenBSC# ") | |
| 31 | + | conn.write(b"disable\n") | |
| 32 | + | conn.read_until(b"OpenBSC> ") | |
| 33 | + | ||
| 34 | + | def get_users(): | |
| 35 | + | # returns user id list generator | |
| 36 | + | ||
| 37 | + | db = sqlite3.connect(HLR_DATABASE) | |
| 38 | + | c = db.cursor() | |
| 39 | + | c.execute("SELECT * FROM Subscriber") | |
| 40 | + | ||
| 41 | + | for subscriber in c.fetchall(): | |
| 42 | + | yield subscriber[0] | |
| 43 | + | ||
| 44 | + | def send_sms(id, extension, message): | |
| 45 | + | conn.write(b"subscriber id %d sms sender extension %s send %s\n" % (id, extension, message)) | |
| 46 | + | res = conn.read_until(b"OpenBSC> ") | |
| 47 | + | if b"%" in res: | |
| 48 | + | print(res) | |
| 49 | + | exit(1) | |
| 50 | + | ||
| 51 | + | if __name__ == "__main__": | |
| 52 | + | try: | |
| 53 | + | extension = sys.argv[1] | |
| 54 | + | message = " ".join(sys.argv[2:]) | |
| 55 | + | except: | |
| 56 | + | print("usage: ./sms_broadcast.py extension message") | |
| 57 | + | print("This script sends a message from the specified extension (number) to all devices connected to this base station") | |
| 58 | + | exit(1) | |
| 59 | + | ||
| 60 | + | conn = telnetlib.Telnet("127.0.0.1", 4242) | |
| 61 | + | conn.read_until(b"OpenBSC> ") | |
| 62 | + | ||
| 63 | + | check_extension(extension) | |
| 64 | + | ||
| 65 | + | for id in get_users(): | |
| 66 | + | send_sms(id, extension, message) | |
sms_spam.py(fájl létrehozva)
| @@ -0,0 +1,61 @@ | |||
| 1 | + | #!/usr/bin/env python | |
| 2 | + | import telnetlib | |
| 3 | + | import sys | |
| 4 | + | import random | |
| 5 | + | import time | |
| 6 | + | ||
| 7 | + | imsi = 999999999999999 | |
| 8 | + | ||
| 9 | + | def check_extension(extension): | |
| 10 | + | conn.write(b"show subscriber extension %s\n" % extension) | |
| 11 | + | res = conn.read_until(b"OpenBSC> ") | |
| 12 | + | ||
| 13 | + | if b"No subscriber found for extension" in res: | |
| 14 | + | print("Phone with extension %s not found ;(" % extension) | |
| 15 | + | exit(1) | |
| 16 | + | ||
| 17 | + | def check_spam_subscriber(): | |
| 18 | + | conn.write(b"show subscriber imsi %d\n" % imsi) | |
| 19 | + | res = conn.read_until(b"OpenBSC> ") | |
| 20 | + | ||
| 21 | + | if b"No subscriber found for imsi" in res: | |
| 22 | + | conn.write(b"subscriber create imsi %d\n" % imsi) | |
| 23 | + | print(conn.read_until(b"OpenBSC> ")) | |
| 24 | + | ||
| 25 | + | def send(extension, spam_number, message): | |
| 26 | + | print("Sending sms from %d..." % spam_number) | |
| 27 | + | ||
| 28 | + | conn.write(b"enable\n") | |
| 29 | + | conn.read_until(b"OpenBSC# ") | |
| 30 | + | conn.write(b"subscriber imsi %d extension %d\n" % (imsi, spam_number)) | |
| 31 | + | conn.read_until(b"OpenBSC# ") | |
| 32 | + | conn.write(b"disable\n") | |
| 33 | + | conn.read_until(b"OpenBSC> ") | |
| 34 | + | ||
| 35 | + | conn.write(b"subscriber extension %s sms sender extension %d send %s\n" % (extension, spam_number, message)) | |
| 36 | + | res = conn.read_until(b"OpenBSC> ") | |
| 37 | + | ||
| 38 | + | if b"%" in res: | |
| 39 | + | print(res) | |
| 40 | + | exit(1) | |
| 41 | + | ||
| 42 | + | if __name__ == "__main__": | |
| 43 | + | try: | |
| 44 | + | extension = sys.argv[1] | |
| 45 | + | repeats = int(sys.argv[2]) | |
| 46 | + | message = " ".join(sys.argv[3:]) | |
| 47 | + | except: | |
| 48 | + | print("usage: ./sms_spam.py extension [num of repeats] message") | |
| 49 | + | print("This script sends a message to specified number") | |
| 50 | + | exit(1) | |
| 51 | + | ||
| 52 | + | conn = telnetlib.Telnet("127.0.0.1", 4242) | |
| 53 | + | conn.read_until(b"OpenBSC> ") | |
| 54 | + | ||
| 55 | + | check_extension(extension) | |
| 56 | + | check_spam_subscriber() | |
| 57 | + | ||
| 58 | + | for _ in range(repeats): | |
| 59 | + | spam_number = random.randint(1000,9999) | |
| 60 | + | send(extension, spam_number, message) | |
| 61 | + | time.sleep(2) | |
Újabb
Régebbi