require "Gelo"
Fuzzer = {}
Fuzzer.default_luadir = ProgDir..'Scripts\\Fuzzer\\'
Fuzzer.default_filters = [[
-- Add your Lua filters here. Examples:
-- if http.statuscode == 404 then canlog = false end
-- if regex_match(http.text,'someregex') == false then canlog = false end
-- if wildmatch(string.lower(http.text),'*error*') == false then canlog = false end
]]
function Fuzzer:displaydiv(name,bool)
if bool == false then
extbar.setstyleattrib('div[name="'..name..'"]','display','none')
else
extbar.setstyleattrib('div[name="'..name..'"]','display','block')
end
end
function Fuzzer:mode_changed()
local newmode = extbar.getval('select[name="mode"]')
extbar.setval('input[name="start"]','0')
extbar.setval('input[name="end"]','100')
self:displaydiv('increment',false)
self:displaydiv('startend',false)
self:displaydiv('character',false)
self:displaydiv('wordlist',false)
if newmode == 'wordlist' then
self:displaydiv('wordlist',true)
end
if newmode == 'number' then
self:displaydiv('increment',true)
self:displaydiv('startend',true)
end
if newmode == 'char_repeat' then
self:displaydiv('increment',true)
self:displaydiv('startend',true)
self:displaydiv('character',true)
extbar.setval('input[name="start"]','1')
end
if newmode == 'ascii' then
self:displaydiv('startend',true)
extbar.setval('input[name="start"]','32')
extbar.setval('input[name="end"]','126')
end
end
function Fuzzer:openlua()
local f = extbar.getval('select[name="scriptlist"]')
local fcontents = ''
if file_exists(self.default_luadir..f) then
fcontents = file_gettostr(self.default_luadir..f)
end
extbar.setval('plaintext[name="script"]',fcontents)
end
function Fuzzer:get_scriptlist()
local p = GStrListParser:new()
local flist = GStrList:new()
local l = file_getdirfiles(self.default_luadir..'*.lua')
p:loadfromstr(l)
while p:parsing() do
flist:add('')
end
local result = flist.text
flist:release()
p:release()
return result
end
function Fuzzer:drawui(req,script)
html = [[
Mode:
Start - End:
-
Increment:
Character:
Base Request:
External Filters: (Place your .lua filters in ]]..ProgDir..[[Scripts\Fuzzer\)
Filter:
]]
extbar.load(html..Fuzzer:get_scriptlist()..html_end)
extbar.setval('plaintext[name="request"]',str_replace(req,' HTTP/','{$1} HTTP/'))
extbar.setval('plaintext[name="script"]',script)
end
function Fuzzer:do_req(value)
if cancel == false then
app.processmessages()
http:clearresponse()
canlog = true
local request = str_replace(baserequest,'{$1}',value)
http:openlow(host,port,request)
if http.error == 0 then
assert(loadstring(script))()
if canlog == true then
tab:logrequest('Fuzzer Request',http.contentlength,http:sentheader(),http:rcvdheader(),http.text)
end
end
end -- cancel end
end
function Fuzzer:run_wordlist()
local wordlistfile = extbar.getval('input[name="wordlist"]')
if file_exists(wordlistfile) then
local list = file_gettostr(wordlistfile)
p = GStrListParser:new()
p:loadfromstr(list)
while p:parsing() do
self:do_req(p.current)
end
p:release()
end
end
function Fuzzer:run_number()
local i=i_start
while i <= i_end do
self:do_req(i)
i = i+i_inc
end
end
function Fuzzer:run_ascii()
for i=i_start,i_end do
self:do_req(string.char(i))
end
end
function Fuzzer:run_charrepeat()
local char = extbar.getval('input[name="char"]')
local i=i_start
while i <= i_end do
self:do_req(string.rep(char,i))
i = i+i_inc
end
end
function Fuzzer:sendrequests()
cancel = false
tab.statusbartext = 'Sending requests...'
extbar.setattrib('button[name="run"]','disabled','True')
extbar.setattrib('button[name="reset"]','disabled','True')
extbar.setattrib('img[name="ani"]','src','Resources.pak#icon_loading.gif')
app.processmessages()
tstart = os.time ()
http = GHTTPRequest:new()
http.autocontentlength = true
host = url_gethost(tab.url)
port = url_getport(tab.url)
if http_getfield(request,'Host') ~= '' then
host = http_getfield(request,'Host')
host = str_trim(host)
port = 80
if wildmatch(host,'*:*') then
port = str_after(host,':')
host = str_before(host,':')
end
end
tab:viewheaders()
local mode = extbar.getval('select[name="mode"]')
i_start = tonumber(extbar.getval('input[name="start"]'))
i_end = tonumber(extbar.getval('input[name="end"]'))
i_inc = tonumber(extbar.getval('input[name="inc"]'))
script = extbar.getval('plaintext[name="script"]')
baserequest = extbar.getval('plaintext[name="request"]')..'\n\n'
if mode == 'wordlist' then self:run_wordlist() end
if mode == 'number' then self:run_number() end
if mode == 'ascii' then self:run_ascii() end
if mode == 'char_repeat' then self:run_charrepeat() end
http:release()
tend = os.time ()
tab:log(os.difftime (tend , tstart) ..' second(s)')
extbar.setattrib('button[name="run"]','disabled','')
extbar.setattrib('button[name="reset"]','disabled','')
extbar.setattrib('img[name="ani"]','src','Resources.pak#icon_blank.png')
if cancel == true then
tab.statusbartext = 'Aborted.'
else
tab.statusbartext = 'Done.'
end
end
function Fuzzer:loadfromreqeditor()
local baserequest = extbar.getval('plaintext[name="request"]')..'\n\n'
self:drawui(baserequest,self.default_filters)
end
function Fuzzer:viewfuzzer()
if str_beginswith(tab.url,'http') then
http = GHTTPRequest:new()
http:open('GET',tab.url)
self:drawui(http:sentheader(),self.default_filters)
http:release()
else
app.showmessage('No URL loaded.')
end
end