Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ RUN apk add --no-cache tini
# Set the working directory inside the container
WORKDIR /app

ENV MIX_ENV=prod

RUN mkdir output/
RUN chmod 777 output/

Expand Down
67 changes: 43 additions & 24 deletions lib/binoculo/args.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,45 @@ defmodule Binoculo.Args do

def parse_args(argv) do
version = Util.version()
no_args = Enum.empty?(argv)
is_api = Enum.any?(argv, fn arg -> arg in ["--server", "-s"] end)

host_notation_config = [
value_name: "host_notation",
long: "--range",
help: "CIDR or IP range: 192.168.1.0/24 or 192.168.1.0..192.168.1.255",
parser: fn notation ->
case Util.parse_range_or_cidr_notation(notation) do
{:error, _} -> {:error, "invalid cidr or notation"}
{:ok, _} -> {:ok, notation}
end
end,
required:
if no_args or is_api do
false
else
true
end
]

port_config = [
value_name: "port(s)",
short: "-p",
long: "--port",
help: "Port(s) to scan: 80,443,8080 or 80-8080 or 21,80-8080",
parser: fn port ->
case Util.parse_ports_notation(port) do
{:error, _} -> {:error, "invalid port(s)"}
{:ok, port_parsed} -> {:ok, port_parsed}
end
end,
required:
if no_args or is_api do
false
else
true
end
]

optimus =
Optimus.new!(
Expand All @@ -31,29 +70,8 @@ defmodule Binoculo.Args do
]
],
options: [
host_notation: [
value_name: "host_notation",
long: "--range",
help: "CIDR or IP range: 192.168.1.0/24 or 192.168.1.0..192.168.1.255",
parser: fn notation ->
case Util.parse_range_or_cidr_notation(notation) do
{:error, _} -> {:error, "invalid cidr or notation"}
{:ok, _} -> {:ok, notation}
end
end
],
ports: [
value_name: "port(s)",
short: "-p",
long: "--port",
help: "Port(s) to scan: 80,443,8080 or 80-8080 or 21,80-8080",
parser: fn port ->
case Util.parse_ports_notation(port) do
{:error, _} -> {:error, "invalid port(s)"}
{:ok, port_parsed} -> {:ok, port_parsed}
end
end
],
host_notation: host_notation_config,
ports: port_config,
output: [
value_name: "output",
short: "-o",
Expand All @@ -66,7 +84,8 @@ defmodule Binoculo.Args do
with {:ok, _file} <- File.open("output/#{output}", [:append]) do
{:ok, output}
end
end
end,
default: "output.txt"
],
write: [
value_name: "write",
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule Binoculo.MixProject do
[
app: :binoculo,
version: "1.3.0",
elixir: "~> 1.18",
elixir: "~> 1.17",
start_permanent: Mix.env() == :prod,
deps: deps(),
test_coverage: [
Expand Down