Exemplo n.º 1
0
def handle_APN(socket, address):

    print 'New APN connection from %s:%s' % address
    received_data = socket.recv()
    unpack_received_data(received_data)

    if not responses_saved:
        socket.settimeout(1)
        try:
            socket.recv(64)
        except:
            pass
    else:
        response = responses_saved.popleft()
        socket.sendall(response)
Exemplo n.º 2
0
def handle_APN(socket, address):

    print 'New APN connection from %s:%s' % address
    received_data = socket.recv()
    unpack_received_data(received_data)

    if not responses_saved:
        socket.settimeout(1)
        try:
            socket.recv(64)
        except:
            pass
    else:
        response = responses_saved.popleft()
        socket.sendall(response)
Exemplo n.º 3
0
def handleTCP(socket, address):
    global ttl, httpData
    socket.settimeout(ttl)
    httpFlag = False
    ip, port = address
    buf = ""
    dport = 0
    try:
        dport = int(os.popen("grep \"src=%s\" /proc/net/nf_conntrack | grep tcp | grep \"sport=%d\"| tail -n 1" % (ip, port,)).read().split("dport=", 1)[1].split(" ", 1)[0])
    except:
        pass

    if dport == 0:
        try:
            dport = int(os.popen("grep \"src=%s\" /proc/net/ip_conntrack | grep tcp | grep \"sport=%d\"| tail -n 1" % (ip, port,)).read().split("dport=", 1)[1].split(" ", 1)[0])
        except:
            pass
    log = "[+] TCP Connection on Port: %d from %s:%d Time: %s\n" % (dport, ip, port, datetime.utcnow().isoformat())
    print log,
    with open("logs.txt", "a") as f:
        f.write(log)
        f.close()
    try:
        if dport in [443] or 443 == dport%1000:
            context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
            context.load_cert_chain(certfile="ssl.crt", keyfile="ssl.key")
            context.options = ssl.OP_ALL
            try:
                sslsock = context.wrap_socket(socket, server_side=True)
                while True:
                    buffer = sslsock.read()
                    if not buffer:
                        sslsock.send(httpData)
                        break
                    buf+=buffer
                    if checkHTTP(buf):
                        httpFlag = True

            except Exception as e:
                print "[-] Error: %s" % (e,)
            finally:
                    try:
                        sslsock.close()
                    except:
                        pass
        elif dport in [23]:
            socket.send("login: "******"\n":
                    buf+= buffer
                    break
                else:
                    buf+=buffer
            if not socket.closed:
                socket.send("Password: "******"\n":
                    buf+= buffer
                    socket.send("XM# ")
                    break
                else:
                    buf+=buffer
            while not socket.closed:
                
                buffer = recv(socket)
                if not buffer:
                    socket.close()
                    break
                elif buffer == "\n":
                    tosend = telnetparse(buf.split("\n")[-1])
                    if tosend <> None:
                        socket.send(tosend)
                        socket.send("\n")
                    buf+= buffer
                    socket.send("XM# ")
                else:
                    buf+= buffer 
                
                   

        else:
            while not socket.closed:
                buffer = recv(socket)
                if not buffer:
                    if httpFlag:
                        socket.send(httpData)
                    socket.close()
                    break
                else:
                    buf+= buffer
                    if checkHTTP(buf):
                        httpFlag = True
       
    except Exception as e:
        print "[-] Error : %s " % (e,)
    with open("captures/tcp/%d_%s_%d_%s.txt" % (dport, ip, port, datetime.utcnow().isoformat().replace(":", "-").replace(".", "-"),) , "wb") as file:
        file.write(buf)
        file.close()    
 def _accept(self, socket, address):
     socket.settimeout(None)
     conn = WorkerConnection(socket, address)
     self._conn_handler(conn)
Exemplo n.º 5
0
 def handle(self, socket, address):
     socket.settimeout(self.__socket_timeout)
     return gevent.pywsgi.WSGIServer.handle(self, socket, address)
Exemplo n.º 6
0
def handleTCP(socket, address):
    global ttl, httpData
    socket.settimeout(ttl)
    httpFlag = False
    ip, port = address
    buf = ""
    dport = 0
    try:
        dport = int(
            os.popen(
                "grep \"src=%s\" /proc/net/nf_conntrack | grep tcp | grep \"sport=%d\"| tail -n 1"
                % (
                    ip,
                    port,
                )).read().split("dport=", 1)[1].split(" ", 1)[0])
    except:
        pass

    if dport == 0:
        try:
            dport = int(
                os.popen(
                    "grep \"src=%s\" /proc/net/ip_conntrack | grep tcp | grep \"sport=%d\"| tail -n 1"
                    % (
                        ip,
                        port,
                    )).read().split("dport=", 1)[1].split(" ", 1)[0])
        except:
            pass
    log = "[+] TCP Connection on Port: %d from %s:%d Time: %s\n" % (
        dport, ip, port, datetime.utcnow().isoformat())
    print log,
    with open("logs.txt", "a") as f:
        f.write(log)
        f.close()
    try:
        if dport in [443] or 443 == dport % 1000:
            context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
            context.load_cert_chain(certfile="ssl.crt", keyfile="ssl.key")
            context.options = ssl.OP_ALL
            try:
                sslsock = context.wrap_socket(socket, server_side=True)
                while True:
                    buffer = sslsock.read()
                    if not buffer:
                        sslsock.send(httpData)
                        break
                    buf += buffer
                    if checkHTTP(buf):
                        httpFlag = True

            except Exception as e:
                print "[-] Error: %s" % (e, )
            finally:
                try:
                    sslsock.close()
                except:
                    pass
        elif dport in [23]:
            socket.send("login: "******"\n":
                    buf += buffer
                    break
                else:
                    buf += buffer
            if not socket.closed:
                socket.send("Password: "******"\n":
                    buf += buffer
                    socket.send("XM# ")
                    break
                else:
                    buf += buffer
            while not socket.closed:

                buffer = recv(socket)
                if not buffer:
                    socket.close()
                    break
                elif buffer == "\n":
                    tosend = telnetparse(buf.split("\n")[-1])
                    if tosend <> None:
                        socket.send(tosend)
                        socket.send("\n")
                    buf += buffer
                    socket.send("XM# ")
                else:
                    buf += buffer

        else:
            while not socket.closed:
                buffer = recv(socket)
                if not buffer:
                    if httpFlag:
                        socket.send(httpData)
                    socket.close()
                    break
                else:
                    buf += buffer
                    if checkHTTP(buf):
                        httpFlag = True

    except Exception as e:
        print "[-] Error : %s " % (e, )
    with open(
            "captures/tcp/%d_%s_%d_%s.txt" %
        (
            dport,
            ip,
            port,
            datetime.utcnow().isoformat().replace(":", "-").replace(".", "-"),
        ), "wb") as file:
        file.write(buf)
        file.close()
    grabHTTP(buf, "tcp", ip, port, dport)