pystack Package

pystack Package

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/.

kernel_filter Module

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/.

pystack.kernel_filter.block_icmp_port_unreachable()[source]

Blocks ICMP port unreachable packets sent by the kernel when a UDP port is hit without any service listening.

pystack.kernel_filter.block_outgoing_packets(proto, ipsrc=None, portsrc=None, ipdst=None, portdst=None)[source]

Blocks outgoing packets coming from the kernel using iptables command.

pystack.kernel_filter.unblock_icmp_port_unreachable()[source]

Remove the rule that blocks ICMP port unreachable.

pystack.kernel_filter.unblock_outgoing_packets(proto, ipsrc=None, portsrc=None, ipdst=None, portdst=None)[source]

Unblocks outgoing packets coming from the kernel using iptables command.

pystack Module

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/.

class pystack.pystack.PyStack(iface=None)[source]

Bases: object

PyStack is the class that wrap all the layers together. It builds an entire stack linking all the layers. It implement the Singleton Pattern. So within a script or across modules if they all create a Pystack object only one will be instantiated and all the connections and request will be handled by this one. It provides a method call register_tcp_application to attach a TCP application to the stack like a server or a client. Of course the stack should be started with run to start listening packet and stop to stop listening packets.

instance = None
instanciated = False
is_tcp_port_free(p)[source]

Return either or not the port sent in parameter is free

is_udp_port_free(p)[source]

Return either or not the port sent in parameter is free

register_tcp_application(app)[source]

Register a TCP application on the stack. So basically create a tcp session for the app and attach the TCPSession to the TCP layer.

register_udp_application(app)[source]

Register the given app as an UDP application.

run(doreactor=True)[source]

Just call the start_listening of the Ethernet layer (which hold the ScapyIO). Except for reactor which normally catch SIGINT to stop the reactor. Here we catch the SIGINT oursleves and stop the reactor by changing a boolean (which is tested periodically)

running = False
stop()[source]

Stop will stop the stack. But to make it ‘smartly’ try for every connections of the tcp layer to call the close method if it exists. Then wait 5 seconds to be sure that all the connections have the time to stop and then stop the stack itself.

pystack_socket Module

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/.

pystack.pystack_socket.create_connection(address, timeout=None, source_address=None)[source]

Create a connection and return the socket connected

pystack.pystack_socket.gethostname()[source]

Return the hostname

class pystack.pystack_socket.socket(family=2, type=1, proto=0, app=None)[source]

socket class that will replace the genuine one located in _socket

accept()[source]

accept a connect in case of TCP Socket, raise an error for UDP

bind((host, port))[source]

Bind the application on the given port regardless of if this is an UDP or TCP socket

close()[source]

Call the close function of the app

connect((host, port))[source]

Call connect of the app (also valid for UDP)

connect_ex((host, port))[source]

See real socket module for info

fileno()[source]

Should be implemented in order to fake socket class. Does not do what expected may imply the app to crash if called.

getpeername()[source]

Return the remote IP, port of the peer

getsockname()[source]

Return local IP, port

getsockopt(level, optname, bufflen=None)[source]

Not implemented but needed to fake socket class

gettimeout()[source]

Return the if blocking or not

ioctl(control, option)[source]

Not implemented

listen(backlog=0)[source]

Call app listen method of TCPApplication

makefile(mode=None, bufsize=None)[source]

Not implemented

recv(bufsize, flags=0)[source]

Read informations received in the TCPApplication

recv_into(buffer, nbytes=None, flags=0)[source]

Write received bytes in the given buffer. (not tested)

recvfrom(bufsize, flags=0)[source]

Return information received in the socket, but also the originating peer

recvfrom_into(buffer, nbytes=None, flags=0)[source]

Write received bytes in the given buffer. (not tested)

send(string, flags=0)[source]

Send the given data in the socket

sendall(string, flags=0)[source]

Also send the given data in the socket

sendto(string, address)[source]

Send data to the given host. TCP ignore address. UDP send to the right hosts

setblocking(flag)[source]

Set a boolean to make read write blocking or not

setsockopt(level, optname, value)[source]

Not implemented

settimeout(flag=None)[source]

Not implemented. Define binary a timeout for blocking read/write

shutdown(how)[source]

Not implemented

stop()[source]

Stop the associated application

Table Of Contents

This Page