Commit 30c83bb6 authored by dmknght's avatar dmknght

Add some handle for extensions

parent 1280fd63
Pipeline #1246 failed with stages
src/test/test
src/test/args
src/test/testcli
src/test/testmain
src/dirbnim
\ No newline at end of file
......@@ -11,7 +11,7 @@
{
"label": "[Test]Show user options",
"type": "shell",
"command": "nim c -r src/test/testargs.nim a.b -w x"
"command": "nim c -r src/test/testargs.nim a.b -w /usr/share/wordlists/dirb/common.txt -t -T 32"
},
{
"label": "[Test]Test run connection",
......
# 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
# TODO skip `/` for extension like (a.exe)
when isMainModule:
echo("Hello, World!")
import modules / cli / getOpts
import modules / cores / [connection, options]
var userOpts = getOptions().checkExtensions()
if not userOpts.paramError:
for subPath in lines(userOpts.wordlist):
checkBranch(subPath, userOpts)
# import tables
import os
import .. / cores / paramHandler
import .. / cores / [paramHandler, options]
import strutils
import utils
import help
type
DirbOptions* = object
url*: string
wordlist*: string
cookie*: string
agent*: string
paramError*: bool
maxThreads*: int
proc getOptions*(): DirbOptions =
var allOptions: DirbOptions
allOptions = DirbOptions(
wordlist: "/usr/share/dirb/wordlists/common.txt",
paramError: false,
maxThreads: 32
maxThreads: 64,
add_slash: true
)
let
......@@ -51,6 +41,21 @@ proc getOptions*(): DirbOptions =
allOptions.cookie = paramStr(i + 1)
of "-a":
allOptions.agent = paramStr(i + 1)
of "-p":
allOptions.proxy_addr = paramStr(i + 1)
of "-P":
allOptions.proxy_cred = paramStr(i + 1)
of "-U":
allOptions.basic_auth = paramStr(i + 1)
of "-x":
allOptions.extensions = paramStr(i + 1)
of "-X":
allOptions.extension_file = paramStr(i + 1)
of "-t":
allOptions.add_slash = false
i -= 1
of "-T":
allOptions.maxthreads = parseInt(paramStr(i + 1))
else:
if paramStr(i).startsWith("-"):
if paramStr(i) in helpKeywords:
......
import httpclient
# import strutils
import .. / cli / utils
import options
import strutils
proc checkBranch*(subPath, fullURL: string) =
proc checkBranch*(subPath: string, opts: DirbOptions) =
let fullURL = opts.url & subPath
# TODO use a callback function instead of progressbar cli
progressBar(fullURL)
# TODO use a callback function instead of cli
# TODO http header crafting here
var client = newHttpClient()
try:
let resp = client.get(fullURL)
if resp.status != "404 Not Found":
# TODO use a callback function instead of cli
# TODO use a callback function instead of print cli
prntFound(resp.status, fullURL)
# TODO do a sub branch append for later scan
if opts.add_slash and not fullURL.endsWith("/"):
progressBar(fullURL & "/")
let slash_resp = client.get(fullURL & "/")
if slash_resp.status != "404 Not Found":
# TODO use a callback function instead of print cli
prntFound(resp.status, fullURL & "/")
if len(opts.final_extensions) != 0:
for thisExtension in opts.final_extensions:
let extResp = client.get(fullURL & thisExtension)
progressBar(fullURL & thisExtension)
if extResp.status != "404 Not Found":
# TODO use a callback function instead of print cli
prntFound(extResp.status, fullURL & thisExtension)
except ProtocolError:
# TODO use a callback function instead of print cli
prntErr(fullURL, "ProtocolError")
except:
echo getCurrentExceptionMsg()
echo repr(getCurrentException())
# TODO use a callback function instead of print cli
prntErr(fullURL, "Unknown")
finally:
client.close()
import strutils
import os
type
DirbOptions* = object
maxThreads*: int
paramError*: bool
url*: string
wordlist*: string
cookie*: string
agent*: string
proxy_addr*: string
proxy_cred*: string
basic_auth*: string
add_slash*: bool
extensions*: string
extension_file*: string
final_extensions*: seq[string]
proc checkExtensions*(opt: DirbOptions): DirbOptions =
result = opt
if opt.extensions == "" and opt.extension_file == "":
return opt
elif opt.extensions != "":
for thisExt in opt.extensions.split(","):
if not thisExt.startsWith("."):
result.final_extensions.add("." & thisExt)
else:
result.final_extensions.add(thisExt)
elif opt.extension_file != "":
if fileExists(opt.extension_file):
for line in lines(opt.extension_file):
if not line.startsWith("."):
result.final_extensions.add("." & line)
else:
result.final_extensions.add(line)
else:
result.paramError = true
else:
result.paramError = true
import cpuinfo, times, math, threadpool
# Bench script
# ----------------------------------------------------------------------------------------------------
template benchmark*(benchName: string, body: untyped) =
# When multithreading, make sure to measure wall-clock time
# If you use CPU time you might measure the cumulated CPU time on each processor.
let start = epochTime()
body
let stop = epochTime()
let elapsed = stop-start
echo "Wall time for ", benchName, ": ", round(elapsed, 3), " s"
# OpenMP
# ----------------------------------------------------------------------------------------------------
# Add OpenMP to compilation flags
{.passC:"-fopenmp".}
{.passL:"-fopenmp".}
# Nim native threading
# ----------------------------------------------------------------------------------------------------
template parallelChunks*(start, stop: int, chunkOffset, chunkSize: untyped{ident}, body: untyped): untyped =
## In-place declare and define "chunkOffset" and "chunkSize"
## That corresponds to a slice of the start..stop range
## that will be processed on the same core
let
numIters = (stop - start)
numChunks = countProcessors()
baseChunkSize = numIters div numChunks
remainder = numIters mod numChunks
# The following simple chunking scheme can lead to severe load imbalance
#
# `chunkOffset`{.inject.} = chunkSize * threadId
# `chunkSize`{.inject.} = if threadId < nb_chunks - 1: chunkSize
# else: numIters - chunkOffset # remainder if division isn't exact
#
# For example dividing 40 items on 12 threads will lead to
# a base_chunk_size of 40/12 = 3 so work on the first 11 threads
# will be 3 * 11 = 33, and the remainder 7 on the last thread.
# Instead of dividing 40 work items on 12 cores into:
# 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 7 = 3*11 + 7 = 40
# the following scheme will divide into
# 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3 = 4*4 + 3*8 = 40
var chunkOffset {.inject.}, chunkSize {.inject.}: Natural
for threadID in 0 ..< numChunks:
if threadID < remainder:
chunkOffset = start + (baseChunkSize + 1) * threadID
chunkSize = baseChunkSize + 1
else:
chunkOffset = start + baseChunkSize * threadID + remainder
chunkSize = baseChunkSize
block: body
# import httpclient
import terminal
# import strutils
import bench
import threadpool
import ../modules/cores/connection
const
url = "http://testphp.vulnweb.com/"
dict = "/usr/share/dirb/wordlists/common.txt"
proc createTest() =
# var client = newHttpClient()
benchmark "ThreadPool loop":
for subPath in lines(dict):
let fullURL = url & subPath
spawn checkBranch(subPath, fullURL)
# client.close()
stdout.eraseLine()
createtest()
switch("threads", "on")
switch("define", "ssl")
\ No newline at end of file
import ../ modules / cli / options
let userOptions = getOptions()
echo userOptions
\ No newline at end of file
import ../ modules / cli / help
helpBanner()
import .. / modules / cli / options
import .. / modules / cores / connection
import threadpool
import httpclient
import strutils
setMaxPoolSize(64)
let allOptions = getOptions()
if not allOptions.paramError:
var client = newHttpClient()
try:
for line in lines(allOptions.wordlist):
if not isEmptyOrWhitespace(line):
let fullURL = allOptions.url & line
# TODO handle / at end of line here
spawn checkBranch(line, fullURL)
if not line.endsWith("/") and not line.contains("."): # and option
# Some web servers support forward to `/` for branches.
spawn checkBranch(line & "/", fullURL & "/")
except:
discard
finally:
client.close()
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