Whisper Library
 All Classes Functions Variables Typedefs Enumerations Friends
whisper_library::NetworkConnector Class Reference

NetworkConnector can send Packets to the Network. More...

Public Member Functions

 NetworkConnector (function< void(string, GenericPacket)> packet_received)
 Constructor of NetworkConnector. More...
 
 ~NetworkConnector ()
 Destructor of NetworkConnector.
 
void sendTcp (string ip, TcpPacket packet)
 Sends a tcp packet to a specific ip. More...
 
void sendUdp (string ip, UdpPacket packet)
 Sends a udp packet to a specific ip. More...
 
bool openListener (string ip, CovertChannel *channel)
 Opens a network listener for packets of a specific ip and covert channel. More...
 
void closeListener (string ip)
 Closes the network listener for a specific ip. More...
 
vector< string > adapters ()
 Returns a vector with available network adapters. More...
 
unsigned int adapterCount ()
 Returns the number of avaiable network adapters.
 
bool setAdapter (string adapter_name)
 Sets the adapter that is used to listen for packets and send them (sending win32 only). More...
 
string currentAdapter ()
 Returns the currently selected adapter name.
 
string adapterDescription (string adapter_name)
 Returns the description of a given network adapter. More...
 
vector< string > adapterAddresses (string adapter_name)
 Returns a vector with all network addesses of an adapter. More...
 

Private Member Functions

void retrievePacket ()
 Loop that retrieves packets from the selected network adapter. More...
 
bool validIPv4 (string ip)
 Checks if the given ip is a valid IPv4 address. More...
 
void addFilter (string ip, unsigned short port, string protocol)
 Adds a capture filter for the opened adapter. More...
 
void removeFilter (string ip)
 Removes a capture filter. More...
 
void rebuildFilter ()
 Has to be called when the filter map 'm_filter' has changed to refresh the capture filter.
 
vector< bool > switchEndian (vector< bool > binary)
 Switches binary from big endian to little endian and the other way around. More...
 
void packetReceived (vector< bool > packet_data)
 Is called in a new thread when a packet is received. More...
 

Private Attributes

PcapWrapperm_pcap
 Pointer to the pcap wrapper. Is used to listen for packets and sending packets.
 
SocketSenderm_socket
 Pointer to a socket class. Is used to send packets using a raw socket.
 
string m_source_ip
 your own ip (ipv4), is set after changing the adapter (setAdapter)
 
unsigned int m_connection_count
 Counts the number of open connections.
 
string m_adapter
 Holds the unique adapter name, that is currently selected.
 
atomic< bool > m_adapter_open
 True, if a network adapter is open. Otherwise false.
 
map< string, string > m_filter
 map, that stores the capture filter rule for every ip. The key is the ip, the capture filter belongs to.
 
function< void(string,
GenericPacket)> 
m_packet_received
 

Detailed Description

NetworkConnector can send Packets to the Network.

A NetworkConnector is used by the ChannelManager to send packets. It can be configured to use a specific network adapter and listen to packets from specific Ip addresses.

Constructor & Destructor Documentation

whisper_library::NetworkConnector::NetworkConnector ( function< void(string, GenericPacket)>  packet_received)

Constructor of NetworkConnector.

Parameters
packet_receivedCallback function that is called, when a packet arrived over network. The first parameter is the ip it was sent from, the second parameter is the application layer part of the packet in a generic format.

Member Function Documentation

vector< string > whisper_library::NetworkConnector::adapterAddresses ( string  adapter_name)

Returns a vector with all network addesses of an adapter.

Parameters
adapter_nameUnique name of the adapter
Returns
Vector of network addresses of the currently selected adapter
string whisper_library::NetworkConnector::adapterDescription ( string  adapter_name)

Returns the description of a given network adapter.

Returns the description of a given network adapter. The unique names of the adapters can be retrieved by calling 'adapters'.

Parameters
adapter_nameUnique name of the adapter
Returns
Description of the adapter. Is empty ("") if the adapter_name wasn't found or the description is NULL.
vector< string > whisper_library::NetworkConnector::adapters ( )

Returns a vector with available network adapters.

Returns a vector with all available network adapter names. The name uniquely identifies the network adapter and is used to select it with 'setAdapter'.

Returns
Vector with all available network adapter names.
void whisper_library::NetworkConnector::addFilter ( string  ip,
unsigned short  port,
string  protocol 
)
private

Adds a capture filter for the opened adapter.

Only packets with matching ip, port and protocol are received. Multiple filters are linked with 'or'. /param ip The ip, that packets are received from in dotted form /param port the port, that received packets should have /param protocol the protocol, that received packets should have

void whisper_library::NetworkConnector::closeListener ( string  ip)

Closes the network listener for a specific ip.

Stops listening for packets coming from the given ip. If no open connection remains, the network adapter is closed.

bool whisper_library::NetworkConnector::openListener ( string  ip,
CovertChannel channel 
)

Opens a network listener for packets of a specific ip and covert channel.

Opens a network adapter that has to be set via 'setAdapter' and listens for packets that are received from the given ip, port and protocol as specified in the covert channel. The listener is started in a seperate thread. Received packets are returned with the callback method set in the constructor.

Parameters
ipThe destination IP of the connection
channelThe covert channel that is used for the connection
Returns
Returns true if the packet listener was started succesfully, otherwise false.
void whisper_library::NetworkConnector::packetReceived ( vector< bool >  packet_data)
private

Is called in a new thread when a packet is received.

The function extracts the application layer header and data from the complete frame and transforms it to little endian. It then calls the callback function m_packet_received to give the packet back to the channelmanager.

Parameters
packet_databinary representation of a complete frame, that was retrieved from an adapter
void whisper_library::NetworkConnector::removeFilter ( string  ip)
private

Removes a capture filter.

Parameters
ipthe ip, that you no longer want to receive messages from
void whisper_library::NetworkConnector::retrievePacket ( )
private

Loop that retrieves packets from the selected network adapter.

Starts a loop that runs as long as an adapter is open. It retrieves packets from the selected adapter and forwards the application layer part via the callback function m_packet_received, that is set in the constructor. Packets are retrieved with a maximum delay of 1 ms.

void whisper_library::NetworkConnector::sendTcp ( string  ip,
TcpPacket  packet 
)

Sends a tcp packet to a specific ip.

Parameters
ipThe ip the packet is send to.
packetThe tcp packet that is send over network.
void whisper_library::NetworkConnector::sendUdp ( string  ip,
UdpPacket  packet 
)

Sends a udp packet to a specific ip.

Parameters
ipThe ip the packet is send to.
packetThe udp packet that is send over network.
bool whisper_library::NetworkConnector::setAdapter ( string  adapter_name)

Sets the adapter that is used to listen for packets and send them (sending win32 only).

Sets the network adapter that is used to listen for incoming packets. Has no effect if an adapter is open. Sending tcp using that adapter is only available on win32 using wpcap. The unique names of the adapters can be retrieved by calling 'adapters'.

Parameters
adapter_nameUnique name of the adapter
Returns
true if the adapter name exists and owns a valid ipv4 address, otherwise false
vector< bool > whisper_library::NetworkConnector::switchEndian ( vector< bool >  binary)
private

Switches binary from big endian to little endian and the other way around.

Returns
Vector that contains the switched binary
bool whisper_library::NetworkConnector::validIPv4 ( string  ip)
private

Checks if the given ip is a valid IPv4 address.

Parameters
ipThe ip to check
Returns
True if the ip is a valid Ipv4 address, otherwise false

Member Data Documentation

function<void(string, GenericPacket)> whisper_library::NetworkConnector::m_packet_received
private

Callback method that is called, when a new packet arrived. First parameter is the ip it was sent from, the second is the application layer part of the packet in a generic format