-
Notifications
You must be signed in to change notification settings - Fork 8
/
SniffVPN.py
116 lines (104 loc) · 3.93 KB
/
SniffVPN.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2016 Alvaro Nunez
#
#This program 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
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
----------------------------------------------------------------------------
SniffVPN -- Analyzer malicious urls over VPN
----------------------------------------------------------------------------
The author is not responsible for any misuse of the application!
"""
## LIBRARIES ##
import os
import subprocess
import logging
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
import argparse
from argparse import RawTextHelpFormatter
from scapy.all import *
from core.banners import get_banner
from core.logger import write_logger
from core.logjson import write_logjson
from core.vtanalyzer import vtanalyzer
from panel.server import *
## CONTEXT VARIABLES ##
version='0.2'
codename='Beta version'
interface='tun0' #Define the interface, tun0 for VPN
serverip = get_ip_address(interface)
serverport = 8000
count=0
logs=None
def parse_args():
parser = argparse.ArgumentParser(description="SniffVPN v{} - '{}'".format(version,codename)+"\nA tool to sniff all HTTP traffic passing through your VPN and analyzer malicious urls",
version="SniffVPN v{} - '{}'".format(version, codename),
usage='python SniffVPN.py [options]',
epilog="The author is not responsible for any misuse of the application",
formatter_class=RawTextHelpFormatter)
#parser.add_argument('-i', dest='interface', type=str, help="Interface to use for sniff, default tun0 for VPN")
parser.add_argument('--nologs', action='store_false', help="Disable logs")
return parser.parse_args()
#Function to detect if VPN is installed
def detectVPN():
#return(os.path.isdir("/etc/openvpn"))
output = subprocess.check_output("ifconfig | grep " + interface + " | wc -l", shell=True)
return output[0]
#Function to get the urls, http only
def packet(x):
getpacket=x.sprintf("{Raw:%Raw.load%\n}")
if getpacket[1:4]=="GET":
list=getpacket.split(r"\r\n")
if len(list)>2:
resource=list[0]
host=list[1]
url=host[6:]+resource[5:(len(resource)-9)]
#Info for logs
time=x.sprintf("%pkt.time%")
ipsrc=x.sprintf("%IP.src%")
ipdst=x.sprintf("%IP.dst%")
portsrc=x.sprintf("%IP.sport%")
portdst=x.sprintf("%IP.dport%")
iporig=getOriginalIP(ipsrc)
if host[6:] != (serverip + ":" + str(serverport)):
write_logjson(time,iporig,ipsrc,ipdst,portsrc,portdst,url)
vtanalyzer(url)
if logs:
write_logger(time,iporig,ipsrc,ipdst,portsrc,portdst,url)
return url+"\n"
#Function to get the original IP
def getOriginalIP(privip):
file=open('/var/log/openvpn-status.log','r')
for line in file:
if line.find(privip)==0:
ipOrig=line.split(',')
file.close()
return ipOrig[2].split(':')[0]
#Function main
def main():
#global interface
global logs
args=parse_args()
#interface=args.interface
logs=args.nologs
if detectVPN() == '1':
print get_banner()
start_server(serverport)
print chr(27) + "[0;92m" + '[*] Running server at ' + serverip + ':' + str(serverport) + '...'
print '[*] Can see statics and logs at ' + serverip + ':' + str(serverport) + '/panel\n' + chr(27) + "[0;0m"
#Start sniff, method from scapy
sniff(iface=interface, prn=packet, count=count)
else:
print 'Installing OpenVPN undetected\nPlease check OpenVPN is installed correctly'
main()