Skip to content

Commit 76d3be6

Browse files
authored
Added path traversal check
1 parent 292142f commit 76d3be6

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

IP-Changer.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ def main():
9090
sys.exit("\033[1;91m[-] Invalid choice.\033[0m")
9191
try:
9292
with tarfile.open(filename, "r:gz") as tar:
93+
members = tar.getmembers()
94+
for member in members:
95+
# Just in case path traversal attack protection
96+
if not os.path.commonpath([os.path.abspath(os.path.join(tor_path, member.name))]).startswith(os.path.abspath(tor_path)):
97+
raise tarfile.TarError(f"Security warning: File '{member.name}' attempts to extract outside '{tor_path}'")
9398
tar.extractall(f"{extract_path}\\Tor Expert Bundle", filter='fully_trusted')
9499
os.remove(filename)
95100
print(f"\033[1;92m[+] Tor has been successfully extracted to the '{extract_path}\\Tor Expert Bundle'\033[0m")

0 commit comments

Comments
 (0)