Commit 05195dc9 authored by dmknght's avatar dmknght

Improve color and exception in connection

parent 017a1ba8
Pipeline #1135 canceled with stages
......@@ -13,5 +13,10 @@
"type": "shell",
"command": "nim c -r src/test/testargs.nim a.b -w x"
}
{
"label": "[Test]Test run connection",
"type": "shell",
"command": "nim c -r src/test/test.nim"
}
]
}
\ No newline at end of file
# This is just an example to get you started. A typical binary package
# uses this file as the main entry point of the application.
# TODO handle `/` at end of branch
# TODO handle end session
# TODO handle time
# TODO threadpool.setMaxPoolSize
when isMainModule:
echo("Hello, World!")
......@@ -3,6 +3,7 @@ import utils
proc fastHelp*() =
# TODO read data from .nimble for dynamic information
echo "DirbNim - A modern URL bruteforcing tool"
echo "Author: Nong Hoang \"dmknght\" Tu <dmknght@parrotsec.org>"
echo "URL: https://nest.parrotsec.org/dmknght/dirbnim"
......
......@@ -10,6 +10,7 @@ type
cookie*: string
agent*: string
paramError*: bool
maxThreads*: int
proc getOptions*(): DirbOptions =
......@@ -17,7 +18,8 @@ proc getOptions*(): DirbOptions =
allOptions = DirbOptions(
wordlist: "/usr/share/wordlists/common.txt",
paramError: false
paramError: false,
maxThreads: 32
)
let
......
import terminal
import strutils
proc showHelpCmd*(app = "dirbnim", keyword = "help", value = "", descr = "") =
......@@ -29,7 +30,7 @@ proc progressBar*(subPath: string) =
proc prntErr*(reason: string, descr = "") =
var msg = "[\e[31mE\e[0m] " # Red
var msg = "[\e[91mE\e[0m] " # Bright red
if descr != "":
msg &= "[\e[36m" & descr & "\e[0m] " # cyan
msg &= "\e[35m" & reason & "\e[0m"
......@@ -37,7 +38,7 @@ proc prntErr*(reason: string, descr = "") =
proc prntWarn*(reason: string, descr = "") =
var msg = "[\e[33mW\e[0m] " # Yellow
var msg = "[\e[93mW\e[0m] " # Bright Yellow
if descr != "":
msg &= "[\e[36m" & descr & "\e[0m] " # cyan
msg &= reason
......@@ -48,4 +49,15 @@ proc prntFound*(status, url: string) =
# TODO color here
stdout.eraseLine()
stdout.flushFile()
echo "[" & status & "] [" & url & "]"
var msg = " [\e[95m" & url & "\e[0m]" # Bright Magenta
if status.startsWith("2"):
msg = "[\e[92m" & status & "\e[0m]" & msg # Bright green
elif status.startsWith("3"):
msg = "[\e[33m" & status & "\e[0m]" & msg # Yellow (orange alike)
elif status.startsWith("4"):
msg = "[\e[31m" & status & "\e[0m]" & msg # Red (a little dark)
elif status.startsWith("5"):
msg = "[\e[96m" & status & "\e[0m]" & msg # Bright Cyan
echo msg
......@@ -7,8 +7,13 @@ proc checkBranch*(client: HttpClient, subPath, fullURL: string) =
if not isEmptyOrWhitespace(subPath):
progressBar(subPath)
# TODO use a callback function instead of cli
let resp = client.get(fullURL)
if resp.status != "404 Not Found":
# TODO use a callback function instead of cli
prntFound(resp.status, fullURL)
# TODO do a sub branch append for later scan
try:
let resp = client.get(fullURL)
if resp.status != "404 Not Found":
# TODO use a callback function instead of cli
prntFound(resp.status, fullURL)
# TODO do a sub branch append for later scan
except ProtocolError:
prntErr(fullURL, "ProtocolError")
except:
prntErr(fullURL, "Unknown")
......@@ -37,5 +37,5 @@ proc validWordlist*(path: string): string =
result = ""
except:
prntErr(path, "Unknown error")
prntErr(path, getCurrentExceptionMsg())
# prntErr(path, getCurrentExceptionMsg())
result = ""
import httpclient
import terminal
import strutils
# import strutils
import bench
import threadpool
import ../modules/cores/connection
const
url = "http://testphp.vulnweb.com/"
dict = "/usr/share/dirb/wordlists/common.txt"
# dict = "list.txt"
# TODO handle url format
{.experimental: "parallel".}
proc simProgressBar(subPath: string) =
stdout.eraseLine()
stdout.write(subPath)
stdout.flushFile()
proc checkPath(client: HttpClient, subPath, fullURL: string) =
if not isEmptyOrWhitespace(subPath):
simProgressBar(subPath)
let fullURL = url & subPath
let resp = client.get(fullURL)
if resp.status != "404 Not Found":
stdout.eraseLine()
echo fullURL & " " & resp.status
proc createTest() =
var client = newHttpClient()
# benchmark "Normal loop":
# for subPath in lines(dict):
# if isEmptyOrWhitespace(subPath):
# continue
# simProgressBar(subPath)
# let fullURL = url & subPath
# let resp = client.get(fullURL)
# if resp.status != "404 Not Found":
# stdout.eraseLine()
# echo fullURL & " " & resp.status
benchmark "ThreadPool loop":
for subPath in lines(dict):
let fullURL = url & subPath
spawn checkPath(client, subPath, fullURL)
spawn checkBranch(client, subPath, fullURL)
client.close()
stdout.eraseLine()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment