Add files via upload

This commit is contained in:
halil ibrahim deniz 2023-05-04 09:53:43 +03:00 committed by GitHub
parent 60a9f532ce
commit f8a4290eac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 256 additions and 0 deletions

21
LICENSE Normal file
View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2023 Halil Ibrahim Deniz
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

80
Readme.md Normal file
View file

@ -0,0 +1,80 @@
# PrivacyNet: Privacy Network
PrivacyNet is an anonymization tool that configures iptables and Tor to route all services, traffic and DNS through the Tor network. This tool allows users to route internet traffic through Tor and hide their real IP address.
## Features
- Installing and removing iptables rules
- Connecting to the Tor network to get its IP address and geolocate it
- Change circuit with a new IP
- Fast and easy to use
## Installation
```
git clone https://github.com/HalilDeniz/PrivacyNet.git`
```
## Requirements
Before you can use PrivacyNet, you need to make sure that you have the necessary requirements installed. You can install these requirements by running the following command:
```
pip install -r requirements.txt
```
## Install Tor
Before you can use PrivacyNet, first you need to install the tor package:
```
apt-get clean
apt-get update
apt-get upgrade
apt-get install tor
```
## Getting Started
Run the following command to use the tool::
```
python3 privacynet.py
```
### Options
- `-l` or `--load`: Tor installs iptables rules.
- `-f` or `--flush`: Flushes the iptables rules to default.
- `-r` or `--refresh`: Changes the circuit and gets a new IP.
- `-i` or `--ip`: Displays the current public IP address.
## Use Cases
You can use the tool as follows:
```
python3 privacynet.py -l
[+] Anonymizer status [ON]
[*] Getting public IP, please wait...
[?] Still waiting for IP address...
[+] Your IP is {ip adresi}
[+] Country: {Country}
[+] City: {city}
```
## Contact
If you have any questions, comments, or suggestions about PrivacyNet, please feel free to contact me:
- LinkedIn: [LinkedIn](https://www.linkedin.com/in/halil-ibrahim-deniz/)
- TryHackMe: [TryHackMe](https://tryhackme.com/p/halilovic)
- Instagram: [Instagram](https://www.instagram.com/deniz.halil333/)
- YouTube: [YouTube](https://www.youtube.com/c/HalilDeniz)
- Email: halildeniz313@gmail.com
## About the Original Author
PrivacyNet is a fork of the original tool called toriptables2, which was created by [Rupe](https://github.com/ruped24). Rupe developed the initial version of the tool two years ago. However, the original tool was written in Python 2.7 and is no longer compatible with the latest versions. Therefore, this forked version, PrivacyNet, has been updated and modified to work with Python 3.
I would like to express my gratitude to Rupe for the inspiration and foundation provided by the original tool. Without his work, this updated version would not have been possible.
If you would like to learn more about the original tool, you can visit the [toriptables2 repository](https://github.com/ruped24/toriptables2).
## License
PrivacyNet is released under the MIT License. See LICENSE for more information.

147
privacynet.py Normal file
View file

@ -0,0 +1,147 @@
#!/usr/bin/env python3
# Update by Deniz version 3.x
from subprocess import call, check_call, CalledProcessError
from os.path import isfile, basename
from os import devnull
from sys import exit, stdout, stderr
from atexit import register
from argparse import ArgumentParser
from json import load
from urllib.request import urlopen
from urllib.error import URLError
from time import sleep
import subprocess
import requests
class PrivacyNet(object):
def __init__(self):
self.local_dnsport = "53" # DNSPort
self.virtual_net = "10.0.0.0/10" # VirtualAddrNetwork
self.local_loopback = "127.0.0.1" # Local loopback
self.non_tor_net = ["192.168.0.0/16", "172.16.0.0/12"]
self.non_tor = ["127.0.0.0/9", "127.128.0.0/10", "127.0.0.0/8"]
self.tor_uid = subprocess.getoutput("id -ur debian-tor") # Tor user uid
self.trans_port = "9040" # Tor port
self.tor_config_file = '/etc/tor/torrc'
self.torrc = r'''
## Inserted by %s for tor iptables rules set
## Transparently route all traffic thru tor on port %s
VirtualAddrNetwork %s
AutomapHostsOnResolve 1
TransPort %s
DNSPort %s
''' % (basename(__file__), self.trans_port, self.virtual_net, self.trans_port, self.local_dnsport)
def geolocate_ip(self, ip):
try:
response = requests.get(f"http://ip-api.com/json/{ip}")
data = response.json()
country = data["country"]
city = data["city"]
return country, city
except Exception as e:
print(f"Error geolocating IP: {e}")
return None, None
def flush_iptables_rules(self):
call(["iptables", "-F"])
call(["iptables", "-t", "nat", "-F"])
def load_iptables_rules(self):
self.flush_iptables_rules()
self.non_tor.extend(self.non_tor_net)
@register
def restart_tor():
fnull = open(devnull, 'w')
try:
tor_restart = check_call(
["service", "tor", "restart"],
stdout=fnull, stderr=fnull)
if tor_restart == 0:
print(" {0}".format(
"[+] Anonymizer status [ON]"))
self.get_ip()
except CalledProcessError as err:
print("[!] Command failed: %s" % ' '.join(err.cmd))
# See https://trac.torproject.org/projects/tor/wiki/doc/TransparentProxy#WARNING
# See https://lists.torproject.org/pipermail/tor-talk/2014-March/032503.html
call(["iptables", "-I", "OUTPUT", "!", "-o", "lo", "!", "-d",self.local_loopback, "!", "-s", self.local_loopback, "-p", "tcp","-m", "tcp", "--tcp-flags", "ACK,FIN", "ACK,FIN", "-j", "DROP"])
call(["iptables", "-I", "OUTPUT", "!", "-o", "lo", "!", "-d",self.local_loopback, "!", "-s", self.local_loopback, "-p", "tcp","-m", "tcp", "--tcp-flags", "ACK,RST", "ACK,RST", "-j", "DROP"])
call(["iptables", "-t", "nat", "-A", "OUTPUT", "-m", "owner", "--uid-owner","%s" % self.tor_uid, "-j", "RETURN"])
call(["iptables", "-t", "nat", "-A", "OUTPUT", "-p", "udp", "--dport",self.local_dnsport, "-j", "REDIRECT", "--to-ports", self.local_dnsport])
for net in self.non_tor:
call(["iptables", "-t", "nat", "-A", "OUTPUT", "-d", "%s" % net, "-j","RETURN"])
call(["iptables", "-t", "nat", "-A", "OUTPUT", "-p", "tcp", "--syn", "-j","REDIRECT", "--to-ports", "%s" % self.trans_port])
call(["iptables", "-A", "OUTPUT", "-m", "state", "--state","ESTABLISHED,RELATED", "-j", "ACCEPT"])
for net in self.non_tor:
call(["iptables", "-A", "OUTPUT", "-d", "%s" % net, "-j", "ACCEPT"])
call(["iptables", "-A", "OUTPUT", "-m", "owner", "--uid-owner", "%s" % self.tor_uid, "-j", "ACCEPT"])
call(["iptables", "-A", "OUTPUT", "-j", "REJECT"])
def get_ip(self):
print(" {0}".format("[\033[92m*\033[0m] Getting public IP, please wait..."))
retries = 0
my_public_ip = None
while retries < 12 and not my_public_ip:
retries += 1
try:
my_public_ip = load(urlopen('https://check.torproject.org/api/ip'))['IP']
except URLError:
sleep(5)
print(" [\033[93m?\033[0m] Still waiting for IP address...")
except ValueError:
break
if not my_public_ip:
my_public_ip = subprocess.getoutput('wget -qO - ifconfig.me')
if not my_public_ip:
exit(" \033[91m[!]\033[0m Can't get public ip address!")
country, city = self.geolocate_ip(my_public_ip)
if country and city:
print(" {0}".format("[\033[92m+\033[0m] Your IP is \033[92m%s\033[0m" % my_public_ip))
print(" {0}".format("[\033[92m+\033[0m] Country: \033[92m%s\033[0m" % country))
print(" {0}".format("[\033[92m+\033[0m] City: \033[92m%s\033[0m" % city))
else:
print(" {0}".format("[\033[92m+\033[0m] Your IP is \033[92m%s\033[0m" % my_public_ip))
print(" {0}".format("[\033[93m!\033[0m] Error geolocating IP"))
if __name__ == '__main__':
parser = ArgumentParser(
description='Tor Iptables script for loading and unloading iptables rules')
parser.add_argument('-l','--load', action='store_true', help='This option will load tor iptables rules')
parser.add_argument('-f', '--flush',action='store_true', help='This option flushes the iptables rules to default')
parser.add_argument('-r','--refresh', action='store_true', help='This option will change the circuit and gives new IP')
parser.add_argument('-i', '--ip', action='store_true', help='This option will output the current public IP address')
args = parser.parse_args()
try:
load_tables = PrivacyNet()
if isfile(load_tables.tor_config_file):
if not 'VirtualAddrNetwork' in open(load_tables.tor_config_file).read():
with open(load_tables.tor_config_file, 'a+') as torrconf:
torrconf.write(load_tables.torrc)
if args.load:
load_tables.load_iptables_rules()
elif args.flush:
load_tables.flush_iptables_rules()
print(" {0}".format("[\033[93m!\033[0m] Anonymizer status \033[91m[OFF]\033[0m"))
elif args.ip:
load_tables.get_ip()
elif args.refresh:
call(['kill', '-HUP', '%s' % subprocess.getoutput('pidof tor')])
load_tables.get_ip()
else:
parser.print_help()
except Exception as err:
print(f"[!] Run as super user: {err[1]}")

8
requirements.txt Normal file
View file

@ -0,0 +1,8 @@
requests
subprocess
os
sys
atexit
argparse
json
urllib3