Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow dirsearch to use a non-default network interface #1323 #1325

Merged
merged 4 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## [Unreleased]
- Support non-default network interface

## [0.4.3] - October 2nd, 2022
- Automatically detect the URI scheme (`http` or `https`) if no scheme is provided
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
- [Akshay Ravi](https://www.linkedin.com/in/c09yc47/)
- [kosyan62](https://https://github.com/kosyan62)
- [Maxence Zolnieurck](https://github.com/mxcezl)
- [huyphan](https://github.com/huyphan)

Special thanks to all the people who are named here!

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ Options:
--max-rate=RATE Max requests per second
--retries=RETRIES Number of retries for failed requests
--ip=IP Server IP address
--interface=NETWORK_INTERFACE
Network interface to use

Advanced Settings:
--crawl Crawl for new paths in responses
Expand Down
1 change: 1 addition & 0 deletions config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ max-retries = 1
# proxies = ["localhost:8080"]
# proxies-file = /path/to/proxies.txt
# replay-proxy = localhost:8000
# network-interface = eth0

[advanced]
crawl = False
Expand Down
15 changes: 13 additions & 2 deletions lib/connection/requester.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
import threading
import time

from requests.adapters import HTTPAdapter
from requests.auth import AuthBase, HTTPBasicAuth, HTTPDigestAuth
from requests.packages import urllib3
from requests_ntlm import HttpNtlmAuth
from requests_toolbelt.adapters.socket_options import SocketOptionsAdapter
from urllib.parse import urlparse

from lib.core.data import options
Expand Down Expand Up @@ -83,9 +83,20 @@ def __init__(self):
if options["data"] and "content-type" not in self.headers:
self.set_header("content-type", guess_mimetype(options["data"]))

socket_options = []
if options["network_interface"]:
socket_options.append(
(socket.SOL_SOCKET, socket.SO_BINDTODEVICE, options["network_interface"].encode("utf-8"))
)

for scheme in ("http://", "https://"):
self.session.mount(
scheme, HTTPAdapter(max_retries=0, pool_maxsize=options["thread_count"])
scheme,
SocketOptionsAdapter(
max_retries=0,
pool_maxsize=options["thread_count"],
socket_options=socket_options,
)
)

def _fetch_agents(self):
Expand Down
1 change: 1 addition & 0 deletions lib/core/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"scheme": None,
"max_rate": 0,
"max_retries": 1,
"network_interface": None,
"ip": None,
"exit_on_error": False,
"crawl": False,
Expand Down
1 change: 1 addition & 0 deletions lib/core/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ def parse_config(opt):
"connection", "scheme", None, ("http", "https")
)
opt.replay_proxy = opt.replay_proxy or config.safe_get("connection", "replay-proxy")
opt.network_interface = opt.network_interface or config.safe_get("connection", "network-interface")

# Advanced
opt.crawl = opt.crawl or config.safe_getboolean("advanced", "crawl")
Expand Down
1 change: 1 addition & 0 deletions lib/parse/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ def parse_arguments():
help="Number of retries for failed requests",
)
connection.add_option("--ip", action="store", dest="ip", help="Server IP address")
connection.add_option("--interface", action="store", dest="network_interface", help="Network interface to use")

# Advanced Settings
advanced = OptionGroup(parser, "Advanced Settings")
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ pyparsing>=2.4.7
beautifulsoup4>=4.8.0
mysql-connector-python>=8.0.20
psycopg[binary]>=3.0
requests-toolbelt>=1.0.0
Loading