Skip to content

Commit

Permalink
control ulimit handler and adjust according to threads
Browse files Browse the repository at this point in the history
  • Loading branch information
Pepelux committed Oct 15, 2024
1 parent 8e911a9 commit 8802662
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
devel:
- scan:
- control ulimit handler and adjust according to threads

v4.1.1 (Oct/2024):
- added new binary: sippts-gui
- global:
Expand Down
38 changes: 34 additions & 4 deletions src/sippts/sipscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from .lib.logos import Logo
from itertools import product
from concurrent.futures import ThreadPoolExecutor

import resource as res

class SipScan:
def __init__(self):
Expand Down Expand Up @@ -84,7 +84,7 @@ def __init__(self):
self.cve = []

self.c = Color()


def stop(self):
try:
Expand All @@ -95,7 +95,37 @@ def stop(self):
self.quit = True


def set_ulimit(self, threads):
# Get current 'ulimit -n' value
soft,ohard = res.getrlimit(res.RLIMIT_NOFILE)
hard = ohard

# If ulimit < threads, set new value
if soft < threads:
# soft = threads * 2
soft = threads + 100

if hard < soft:
hard = soft

try:
res.setrlimit(res.RLIMIT_NOFILE,(soft,hard))
except (ValueError,res.error):
try:
hard = soft
# Trouble with max limit, retrying with soft,hard
res.setrlimit(res.RLIMIT_NOFILE,(soft,hard))
except Exception:
# Failed to set ulimit, setting new threads value
soft,hard = res.getrlimit(res.RLIMIT_NOFILE)
self.threads = soft

soft,hard = res.getrlimit(res.RLIMIT_NOFILE)


def start(self):
self.set_ulimit(self.threads)

supported_protos = ["UDP", "TCP", "TLS"]
supported_methods = ["OPTIONS", "REGISTER", "INVITE"]

Expand Down Expand Up @@ -504,7 +534,7 @@ def scan_host(self, ipaddr, port, proto):

if self.fail > 50:
print(
f"{self.c.RED}Too many socket connection errors. Consider reducing the number of threads or increasing the number of connections using ulimit"
f"{self.c.RED}Too many socket connection errors. Consider reducing the number of threads"
)
self.quit = True
return
Expand Down Expand Up @@ -603,7 +633,7 @@ def scan_host(self, ipaddr, port, proto):
sock_ssl.connect(host)
sock_ssl.sendall(bytes(msg[:8192], "utf-8"))
else:
sock.sendto(bytes(msg[:8192], "utf-8"), host)
sock.sendto(bytes(msg[:8192], "utf-8"), (host))

if self.verbose == 2:
print(
Expand Down

0 comments on commit 8802662

Please sign in to comment.