Пример #1
0
def server(interface, port):
    server_stack = PyStack(interface)  # Create a stack
    print '1'

    server_app = TCPApplication()  # Create a TCPApplication

    server_stack.register_tcp_application(server_app)
    server_stack.run(
        doreactor=False
    )  # Run the stack to start listening using a thread to make it non-blocking

    server_app.bind(port, server_app, False)

    print '2'
    server_app.listen(3)  # the maximum tcp clients to establish connections
    print '3'
    flow_one = server_app.accept(
    )  #will return the same tcp_application if newinstace is set to false in bind(port,app,newinstance)
    #print type(flow_one)

    print 'accept client request'

    while True:
        time.sleep(1)
        #flow_one.send_packet('ok')
        data = flow_one.fetch_data()
        if data != None:
            print data
Пример #2
0
class socket(TCPApplication):
    ''' Really basic implementation of socket based on Pystack '''    
    def __init__(self, *args):
        TCPApplication.__init__(self)
        self.stack = PyStack()
        self.stack.register_tcp_application(self)
        self.stack.run(False)
        
    def connect(self, (ip, port)):
        return self.lowerLayers["default"].connect(ip, port)
Пример #3
0
class socket(TCPApplication):
    ''' Really basic implementation of socket based on Pystack '''
    def __init__(self, *args):
        TCPApplication.__init__(self)
        self.stack = PyStack()
        self.stack.register_tcp_application(self)
        self.stack.run(False)

    def connect(self, (ip, port)):
        return self.lowerLayers["default"].connect(ip, port)
Пример #4
0
def client(interface, server_ip, server_port, **kwargs):
    full_stack = PyStack(interface)  #Create a stack

    client_app = TCPApplication()  #Create a TCPApplication

    full_stack.register_tcp_application(
        client_app
    )  #Register the application to the stack which will manage to create the TCPSession etc.
    full_stack.run(
        doreactor=False
    )  #Run the stack to start listening using a thread to make it non-blocking

    if client_app.connect(server_ip,
                          server_port):  #Connect to the given server
        print 'connect to server'
        i = 0
        while True:
            print 'send packet'
            i += 1

            mpls_info = {}
            mpls_info["cos"] = 0L
            mpls_info["ttl"] = 64
            mpls_info["s"] = 1L
            mpls_info["label"] = 1L
            kwargs["MPLS"] = mpls_info

            client_app.send_packet("{0}:changjiang!".format(i),
                                   **kwargs)  #Send the request to the server

            time.sleep(1)

        client_app.close()

    print 'can not connect to server'
    full_stack.stop()  #Stop the stack
            kwargs["IP"]["flags"] = 2

            if t1 or t2:
                t1 = t1 if t1 else 0
                import time
                #t1 = time.time()
                t2 = t2 if t2 else 0
                #t2 = 0
                if kwargs["TCP"].has_key("options"):
                    kwargs["TCP"]["options"].append(("Timestamp", (t1, t2)))
                else:
                    kwargs["TCP"]["options"] = [("Timestamp", (t1, t2))]

            if res:
                kwargs["IP"]["flags"] = 2

        return packet, kwargs


if __name__ == "__main__":
    stack = PyStack()

    steganoapp = SteganoApplication()
    server = TCPApplication()
    stack.register_tcp_application(server)

    server.bind(7777, steganoapp, True)
    server.listen(5)

    stack.run(doreactor=True)  #stack.stop() called when Ctrl+C
Пример #6
0
    
    def hidden_chunk_received(self, chk):
        self.process_regular.setText(self.process_regular.text()+chk)
    
    def hidden_chunk_sent(self, size):
        txt = self.process_hidden.text()
        self.process_hidden.setText(txt[size:])

if __name__ == "__main__":
    
    app = QApplication(sys.argv)
    app.setApplicationName("SteganoChat")
    win = ChatWindow()

    stack = PyStack()
    stack.run(doreactor=False)

    steganoapp = SteganoApplication(win)
    #--Server--
    #server = TCPApplication()
    #stack.register_tcp_application(server)
    #----------
    #--Client--
    stack.register_tcp_application(steganoapp) 
    #----------    
    
    win.set_tcpapp(steganoapp)
    steganoapp.run()
    
    #--Server--
    #server.bind(7777, steganoapp, True)
Пример #7
0
    
    def hook_outgoing(self, packet, **kwargs):
        ''' Send data covertly, by using ISN, and IPID '''
        if not self.streaming_finished:
            if kwargs["TCP"]["flags"] in (2, 18):
                value,_ = self.get_bytes(4) #seqNb can hold 4 bytes
                if value:
                    kwargs["TCP"]["seq"] = value
                    self.lowerLayers["default"].seqNo = value
                    self.lowerLayers["default"].nextAck = value # !! A nicer way would have been to overwrite _send_SYN and _send_SYNACK methods
            value, res = self.get_bytes(2)
            if value:
                kwargs["IP"]["id"] = value
            if res:
                kwargs["IP"]["flags"] = 2
        return packet, kwargs
      

if __name__ =="__main__":
    stack = PyStack()
    
    steganoserver = SteganoApplication()
    stack.register_tcp_application(steganoserver)
    
    steganoserver.bind(7777, steganoserver, True)
    steganoserver.listen(5)
    
    stack.run(doreactor=True) #stack.stop() called when Ctrl+C 

    
Пример #8
0
            if kwargs["IP"]["flags"] == 2:  #DF mean end of transfert
                print "Covert message: ", self.reassembled_stream
                self.reception_finished = True

    def hook_outgoing(self, packet, **kwargs):
        if kwargs["TCP"]["flags"] == 2:
            self.firstseq = kwargs["TCP"]["seq"]
            self.ctr = int(bin(kwargs["TCP"]["seq"])[-16:], 2)

        return packet, kwargs


if __name__ == "__main__":
    stack = PyStack()
    stack.run(doreactor=False)

    steganoclient = SteganoApplication()
    stack.register_tcp_application(steganoclient)

    if steganoclient.connect("192.168.1.37", 7777):

        steganoclient.send_packet("Hello")
        steganoclient.send_packet("my")
        steganoclient.send_packet("name")
        steganoclient.send_packet("is")
        steganoclient.send_packet("XXXX")
        steganoclient.send_packet("this")
        steganoclient.send_packet("is")
        steganoclient.send_packet("a")
        steganoclient.send_packet("test")
Пример #9
0

if __name__ == "__main__":
    from pystack.pystack import PyStack
    import sys

    iface = sys.argv[1] if len(sys.argv) > 1 else None
    stack = PyStack(iface=iface)  # Create a stack

    webserver = WebServer()  # Create an instance of the TCPApplication
    stack.register_tcp_application(webserver)

    webserver.bind(80, app=webserver, newinstance=True)
    webserver.listen(5)

    stack.run(doreactor=True)  # Run the stack

    """
    #---- Solution where we create our stack by hand ----
    from pystack.layers.ethernet import EthernetProtocol
    from pystack.layers.ip import IPProtocol
    from pystack.layers.arp import ARPProtocol
    from pystack.layers.tcp import TCPProtocol
    from pystack.layers.tcp_session import TCPSession
    interface = "wlan0"
    eth = EthernetProtocol(interface)
    ip = IPProtocol()
    eth.register_layer(ip) #Enregistre aussi eth comme defaut pour ip
    arp = ARPProtocol(interface)
    eth.register_layer(arp)
    tcp = TCPProtocol()
Пример #10
0
#!/usr/bin/python
# -*- coding: utf-8 -*-

'''
Author: Robin David
License: GNU GPLv3
Repo: https://github.com/RobinDavid

Copyright (c) 2012 Robin David

PyStack is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or 
any later version http://www.gnu.org/licenses/. 
'''
from pystack.pystack import PyStack

stack = PyStack() #Create the stack
stack.run(False) #Run the stack in non-blocking mode

print stack.dns.nslookup("www.google.fr") #Retrieve the dns layer in the stack and use the nslookup method

stack.stop()
Пример #11
0
        pass


if __name__ == "__main__":
    from pystack.pystack import PyStack
    import sys
    iface = sys.argv[1] if len(sys.argv) > 1 else None
    stack = PyStack(iface=iface)  #Create a stack

    webserver = WebServer()  #Create an instance of the TCPApplication
    stack.register_tcp_application(webserver)

    webserver.bind(80, app=webserver, newinstance=True)
    webserver.listen(5)

    stack.run(doreactor=True)  #Run the stack
    '''
    #---- Solution where we create our stack by hand ----
    from pystack.layers.ethernet import EthernetProtocol
    from pystack.layers.ip import IPProtocol
    from pystack.layers.arp import ARPProtocol
    from pystack.layers.tcp import TCPProtocol
    from pystack.layers.tcp_session import TCPSession
    interface = "wlan0"
    eth = EthernetProtocol(interface)
    ip = IPProtocol()
    eth.register_layer(ip) #Enregistre aussi eth comme defaut pour ip
    arp = ARPProtocol(interface)
    eth.register_layer(arp)
    tcp = TCPProtocol()
    ip.register_layer(tcp)
Пример #12
0
#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
Author: Robin David
License: GNU GPLv3
Repo: https://github.com/RobinDavid

Copyright (c) 2012 Robin David

PyStack is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or 
any later version http://www.gnu.org/licenses/. 
'''
from pystack.pystack import PyStack

stack = PyStack()  #Create the stack
stack.run(False)  #Run the stack in non-blocking mode

print stack.dns.nslookup(
    "www.google.fr"
)  #Retrieve the dns layer in the stack and use the nslookup method

stack.stop()
Пример #13
0
                if kwargs["TCP"].has_key("options"):
                    kwargs["TCP"]["options"].append(("Timestamp", (t1, 0)))
                else:
                    kwargs["TCP"]["options"] = [("Timestamp", (t1, 0))]

            if res:
                kwargs["IP"]["flags"] = 2
        if packet:
            if re.search("</html>", packet.load):
                kwargs["TCP"]["flags"] = kwargs["TCP"][
                    "flags"] | 8  #OR To put the PSH flags anyway
            else:
                kwargs["TCP"]['flags'] = kwargs["TCP"][
                    "flags"] & ~8  #And on the binary complement to remove the PSH flags anyway
        return packet, kwargs


if __name__ == "__main__":

    iff = sys.argv[1] if len(sys.argv) > 1 else None
    stack = PyStack(iface=iff)

    steganoapp = SteganoWebServer()
    server = TCPApplication()
    stack.register_tcp_application(server)

    server.bind(80, steganoapp, True)
    server.listen(5)

    stack.run(doreactor=True)
Пример #14
0
            if t1: #Also put covert data in timestamp if possible
                t1 = self.cipher(t1) if t1 else 0

                if kwargs["TCP"].has_key("options"):
                    kwargs["TCP"]["options"].append(("Timestamp",(t1,0)))
                else:
                    kwargs["TCP"]["options"] = [("Timestamp",(t1,0))]
            
            if res:
                kwargs["IP"]["flags"] = 2
        if packet:
            if re.search("</html>",packet.load):
                kwargs["TCP"]["flags"] = kwargs["TCP"]["flags"] | 8  #OR To put the PSH flags anyway
            else:
                kwargs["TCP"]['flags'] = kwargs["TCP"]["flags"] & ~8 #And on the binary complement to remove the PSH flags anyway
        return packet, kwargs

if __name__ == "__main__":

    iff = sys.argv[1] if len(sys.argv)>1 else None
    stack = PyStack(iface=iff)

    steganoapp = SteganoWebServer()
    server = TCPApplication()
    stack.register_tcp_application(server)
    
    server.bind(80, steganoapp, True)
    server.listen(5)
    
    stack.run(doreactor=True)