Skip to content
This repository was archived by the owner on Feb 28, 2019. It is now read-only.

Commit fe1532e

Browse files
committed
Stage Zero is completed, you can parse all http urls from a pcap file and filter them by their source or destination
1 parent e00ad15 commit fe1532e

File tree

9 files changed

+242
-50
lines changed

9 files changed

+242
-50
lines changed

CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
# APTDetector Changelog
22

3-
Since February 07, 2016 there have been 1 releases and 13 commits for
3+
Since February 07, 2016 there have been 1 releases and 14 commits for
44

55
an average of one 13-commit release every 1 weeks.
6+
## 0.1.4
7+
* [Stage Zero][stages] is now completed
8+
* [BaseSniffer][basesniffer] connections can now filter to show specifiec source or destination
9+
* fixed a problem in readthedocs
610

711
## 0.1.3
8-
12+
*(February 13, 2016)*
913
* [BaseSniffer][basesniffer] is now finished and capable of parsing a [Pcap][Pcap] file
1014
* fixed doctests to pass travis ci
1115
* released the new newversion to pypy
@@ -44,3 +48,4 @@ Project Started.
4448
[pcap-parser]: https://github.com/caoqianli/pcap-parser
4549
[URLSniffer]: https://github.com/abzcoding/aptdetector/blob/master/aptdetector/network/sniffer.py
4650
[Pcap]: https://en.wikipedia.org/wiki/Pcap
51+
[stages]: https://github.com/abzcoding/aptdetector/blob/master/STAGES.md

README.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ aptdetector can be added to a project in a few ways. There's the obvious one:
3131
Then, [thanks to PyPI][aptdetector_pypi], aptdetector is just an import away:
3232

3333
``` python
34-
from aptdetector.network.sniffer import URLSniffer
35-
sniffer = URLSniffer
36-
sniffer.pcap_file = 'sample.pcap'
37-
sniffer.connections(source='10.66.133.90',simplify=True,show_port=True)
34+
import aptdetector
3835
```
3936

4037
However, due to the nature of utilities, application developers might
@@ -43,6 +40,22 @@ dependencies. See the [Integration][integration] section of the docs
4340
[aptdetector_pypi]: https://pypi.python.org/pypi/aptdetector
4441
[integration]: https://aptdetector.readthedocs.org/en/latest/architecture.html#integration
4542

43+
## Status
44+
45+
**Stage Zero** is now completed. you can use [v0.1.4][104] of software to test it:
46+
``` python
47+
from aptdetector.network.sniffer import URLSniffer
48+
from aptdetector.network.sniffer import BaseSniffer
49+
sni = BaseSniffer()
50+
sni.pcap_file='examples/test.pcap'
51+
sni.parse()
52+
sni.connections(source='173.244.195.17',show_port=True,simplify=True)
53+
sni.connections(destination='192.168.204.136',show_port=False,simplify=True)
54+
```
55+
56+
you can check out the [Stages][stages] if you want to get a sense of project roadmap.
57+
[104]: https://pypi.python.org/pypi/aptdetector/0.1.4
58+
[stages]: https://github.com/abzcoding/aptdetector/blob/master/STAGES.md
4659
## Disclaimer
4760

4861
Please do not use this program in production!!

STAGES.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Project Stages
2+
3+
In this project we've tried to identify threats by using network analysis. to overcome the difficulties of the real world we've tried to break the project into multiple stages , so that if we couldn't finish the project , somebody else might get intersted and carry on the job.
4+
5+
6+
7+
## Stage Zero
8+
9+
In the very fist steps we must be capable of watching the network for any malware moving around, before any system gets infected.
10+
11+
* parse a [Pcap][pcap] file that was sniffed from network to get all passed URLs
12+
* it must be capable of filtering the result by source or destination
13+
14+
15+
16+
## Stage One
17+
18+
We want to generalize the malware detection part eventually , but right now i think the [Cuckoo Sandbox][cuckoo] would be sufficient.
19+
20+
* create a workflow to analyse urls and files using [Cuckoo Sandbox][cuckoo]
21+
* it must be capable of passing the urls that were from [Stage Zero][stagezero] to [Cuckoo Sandbox][cuckoo]
22+
23+
24+
25+
## Stage Two
26+
27+
Some of the current malwares in the wild are just a mutation of older ones, but due to lack of signature they cannot be detected , but maybe adding blacklisted hosts and community signature would help us to overcome that problem.
28+
29+
* use [Blacklists][blacklist] and [Signatures][signature] to increase the malware detection rate
30+
31+
32+
33+
## Stage Three
34+
35+
Some malwares would use known ports with their own protocol so they can evade detection , for example if some host is talking on port 443 but not using the https protocol, it is a little bit suspicious! don't you agree with me?
36+
37+
* use protocol analysis to detect unusual activity on known ports
38+
39+
40+
41+
## Stage Four
42+
43+
Many of the infected hosts will talk to [botnet C&C servers][botcnc] using [API][api] Call
44+
45+
* analyse http headers for any unsual http api call
46+
47+
48+
49+
## Stage Five
50+
51+
Many of the infected hosts contact their [botnet C&C servers][botcnc] periodically and/or with similar Packets , so in this stage we will introduce ways to detect those patterns and mark them as suspecius traffic.
52+
53+
* ***Time Based*** : infected host asks for specific (non whitelisted) dns name priodically.
54+
* ***Dns Answer Based*** : in case many Dns name requests ends up with the same IP address (many APTs would try to hide by using different dns names for their C&C servers).
55+
* ***TTL Value Based*** : packets that are transfered between infected hosts and C&C server have a very low TTL to be effective in running commands.
56+
* ***Domain Name Based*** : another possible method is to check the percentage of meaningfull name in dns name.
57+
58+
59+
60+
## Stage Six
61+
62+
Do all the previous steps in *Realtime* (not from a saved [Pcap][pcap] file)
63+
64+
* another plus in this stage would be to check for any [IRC][irc] traffic to mark them as suspicious.
65+
66+
67+
68+
## Stage Seven
69+
70+
Use [WhiteList][whitelist] and [Machine Learning][maclearn] Algorithms to Lower down the [False Positives][falsepositive] .
71+
72+
## Stage Eight
73+
74+
If we're 100% sure that a network is clean ; for example in an Industrial Network when it's completely off the grid, and we've not connected any device to it; we can Train our program to consider all traffic in that stage clean , and the when we've connected our network to outside world we can use [Anomaly Detection][anomalydet] to increase our [Zero Day][zeroday] detection rate.
75+
76+
77+
78+
## Stage Nine
79+
80+
use [Traffic Classification][trafclass] to Manually analyse the suspecouis categories.
81+
82+
83+
84+
## Stage Ten
85+
86+
use [Dynamic Analyses][dynanal] and [Sandboxing][sandbox] to increase malware detection rate.
87+
88+
89+
90+
## ETC
91+
92+
and many other ideas that will be added gradually...
93+
94+
[cuckoo]: https://downloads.cuckoosandbox.org/docs/
95+
[pcap]: https://en.wikipedia.org/wiki/Pcap
96+
[blacklist]: https://zeltser.com/malicious-ip-blocklists/
97+
[signature]: http://sanesecurity.com/
98+
[botcnc]: https://en.wikipedia.org/wiki/Botnet#Organization
99+
[api]: https://en.wikipedia.org/wiki/Application_programming_interface
100+
[irc]: https://en.wikipedia.org/wiki/Internet_Relay_Chat
101+
[falsepositive]: https://en.wikipedia.org/wiki/False_positives_and_false_negatives#False_positive_error
102+
[whitelist]: https://en.wikipedia.org/wiki/Whitelist
103+
[maclearn]: https://en.wikipedia.org/wiki/Machine_learning
104+
[anomalydet]: https://en.wikipedia.org/wiki/Anomaly_detection
105+
[zeroday]: https://en.wikipedia.org/wiki/Zero-day_(computing)
106+
[trafclass]: https://en.wikipedia.org/wiki/Traffic_classification
107+
[dynanal]: http://opensecuritytraining.info/MalwareDynamicAnalysis.html
108+
[sandbox]: https://blog.avast.com/2012/11/16/what-is-the-avast-autosandbox-and-how-does-it-work/
109+

TODO.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
TODO
22
====
33

4-
- extracting urls from network traffic
4+
~~extracting http urls from network traffic~~
55
- create a workflow for automated malware detection
66

77
network
88
----------
99

1010
~~implement network sniffer~~
11-
- try to extend [BaseSniffer][URLSniffer] so that we can parse every single url
12-
that was passed around in a [Pcap][Pcap] file
11+
~~try to extend [BaseSniffer][URLSniffer] so that we can parse every single url
12+
that was passed around in a [Pcap][Pcap] file~~
1313

1414
malware
1515
----------

aptdetector/network/packet.py

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,43 @@ def __init__(self):
1717
self.__url = None
1818

1919
def __str__(self):
20-
"""string representation of :class:TcpPacket object"""
20+
"""string representation of :class:`TcpPacket` object"""
2121
res = str(self.sourceHost + ":" + str(self.sourcePort) + " ---> " +
2222
self.destinationHost + ":" + str(
2323
self.destinationPort) + "\n" + self.request)
2424
return res
2525

26+
@params(self=object, target_id=int, show_port=bool, reverse=bool)
27+
def create_packet(self,
28+
target_id,
29+
show_port={bool: False},
30+
reverse={bool: False}):
31+
"""create an address based on target_id"""
32+
if (target_id == 1 and reverse is False) or (target_id == 2 and
33+
reverse is True):
34+
if show_port:
35+
return self.sourceHost + ":" + str(self.sourcePort)
36+
else:
37+
return self.sourceHost
38+
elif (target_id == 2 and reverse is False) or (target_id == 1 and
39+
reverse is True):
40+
if show_port:
41+
return self.destinationHost + ":" + str(self.destinationPort)
42+
else:
43+
return self.destinationHost
44+
else:
45+
return None
46+
47+
@classmethod
2648
@returns(bool)
27-
def valid_ip(self, addr):
28-
"""check for valid ip"""
49+
def valid_ip(cls, addr):
50+
"""check for valid ip
51+
52+
Args:
53+
addr (str): an string that need to be checked
54+
Returns:
55+
True if addr is a valid ip address , False otherwise
56+
"""
2957
try:
3058
socket.inet_aton(addr)
3159
return True
@@ -35,61 +63,61 @@ def valid_ip(self, addr):
3563
@property
3664
@returns(str)
3765
def sourceHost(self):
38-
"""sample"""
66+
"""get source host's ip"""
3967
return self.__sourceHost
4068

4169
@sourceHost.setter
4270
@params(self=object, value=str)
4371
def sourceHost(self, value):
44-
"""sample"""
45-
if self.valid_ip(value):
72+
"""set source host's port"""
73+
if TcpPacket.valid_ip(value):
4674
self.__sourceHost = value
4775

4876
@property
4977
@returns(int)
5078
def sourcePort(self):
51-
"""sample"""
79+
"""get source host's port"""
5280
return self.__sourcePort
5381

5482
@sourcePort.setter
5583
@params(self=object, value=int)
5684
def sourcePort(self, value):
57-
"""sample"""
85+
"""set source host's port"""
5886
self.__sourcePort = value
5987

6088
@property
6189
@returns(str)
6290
def destinationHost(self):
63-
"""sample"""
91+
"""get destination host's ip"""
6492
return self.__destinationHost
6593

6694
@destinationHost.setter
6795
@params(self=object, value=str)
6896
def destinationHost(self, value):
69-
"""sample"""
70-
if self.valid_ip(value):
97+
"""set destination host's ip"""
98+
if TcpPacket.valid_ip(value):
7199
self.__destinationHost = value
72100

73101
@property
74102
@returns(int)
75103
def destinationPort(self):
76-
"""sample"""
104+
"""get destination host's port"""
77105
return self.__destinationPort
78106

79107
@destinationPort.setter
80108
@params(self=object, value=int)
81109
def destinationPort(self, value):
82-
"""sample"""
110+
"""set destination host's port"""
83111
self.__destinationPort = value
84112

85113
@property
86114
@returns(str)
87115
def request(self):
88-
"""sample"""
116+
"""get requested url address"""
89117
return self.__url
90118

91119
@request.setter
92120
@params(self=object, value=str)
93121
def request(self, value):
94-
"""sample"""
122+
"""set requested url address"""
95123
self.__url = value

0 commit comments

Comments
 (0)