Skip to content

Commit 59a14ff

Browse files
author
dwfault
committed
merge from internal git repo
1 parent 4c7b31d commit 59a14ff

File tree

3 files changed

+263
-179
lines changed

3 files changed

+263
-179
lines changed

afl-fuzz.c

+121-88
Original file line numberDiff line numberDiff line change
@@ -322,94 +322,125 @@ enum {
322322
};
323323

324324
char WebAssemblyLoadPrefix[] =
325-
"var importObject = {\n\
326-
env: {\n\
327-
print_number: function (number) {\n\
328-
print(\'[+] importObject callback.\');\n\
329-
print(number);\n\
330-
}\n\
331-
}\n\
332-
};\n\
325+
"var importObject = {\
326+
env: {\
327+
i: function (arg1, arg2) {\
328+
arg1 -= arg2;\
329+
var a = arguments.length;\
330+
var b = arguments[2];\
331+
var c = b.__proto__.slice([...b]);\
332+
print(\'[+] imported function executed.\');\
333+
},\
334+
}\
335+
};\
333336
var wasmCode = new Uint8Array([";
334337

335-
char WebAssemblyLoadPostfix[] = "]);\n\
336-
///////////////////////////////////////////////////////////////////////////INIT\n\
337-
try {\n\
338-
var wasmModule = new WebAssembly.Module(wasmCode);\n\
339-
var wasmInstance = new WebAssembly.Instance(wasmModule, importObject);\n\
340-
print(\'[+] wasmCode validate.\');\n\
341-
print(WebAssembly.validate(wasmCode));\n\
342-
}\n\
343-
catch (e) { print(e); }\n\
344-
///////////////////////////////////////////////////////////////////////////EXPORTS\n\
345-
try {\n\
346-
var wasmInstanceExported = wasmInstance.exports;\n\
347-
print(\'[+] wasmInstanceExported.\');\n\
348-
try {\n\
349-
var wasmInstanceExportedTable = wasmInstance.exports.table;\n\
350-
for (var i = 0; i < 100; i++) {\n\
351-
print(wasmInstanceExportedTable.get(i));\n\
352-
}\n\
353-
}\n\
354-
catch (e) { print(e); }\n\
355-
try {\n\
356-
print(wasmInstanceExported.main(0));\n\
357-
}\n\
358-
catch (e) { print(e); }\n\
359-
try {\n\
360-
for (var i in wasmInstanceExported) {\n\
361-
try {\n\
362-
print(eval(\'wasmInstanceExported.\' + i + \';\'));\n\
363-
}\n\
364-
catch (e) { print(e); }\n\
365-
try {\n\
366-
print(eval(\'wasmInstanceExported.\' + i + \'(0);\'));\n\
367-
}\n\
368-
catch (e) { print(e); }\n\
369-
}\n\
370-
}\n\
371-
catch (e) { print(e); }\n\
372-
\
373-
var wasmModuleExports = WebAssembly.Module.exports(wasmModule);\n\
374-
var varExports = [];\n\
375-
print(\'[+] wasmModuleExported.\')\n\
376-
for (var i of wasmModuleExports) {\n\
377-
print(i + \' : \' + i.kind + \' : \' + i.name);\n\
378-
varExports.push(i.name);\n\
379-
}\n\
380-
for (var i of varExports) {\n\
381-
try {\n\
382-
print(eval(\'wasmInstanceExported.\' + i + ';\'));\n\
383-
}\n\
384-
catch (e) { print(e); }\n\
385-
try {\n\
386-
print(eval(\'wasmInstanceExported.\' + i + \'(0);\'));\n\
387-
}\n\
388-
catch (e) { print(e); }\n\
389-
}\n\
390-
}\n\
391-
catch (e) { print(e) };\n\
392-
///////////////////////////////////////////////////////////////////////////IMPORTS\n\
393-
try {\n\
394-
var wasmModuleImports = WebAssembly.Module.imports(wasmModule);\n\
395-
var varImports = [];\n\
396-
print(\'[+] wasmModuleImported.\')\n\
397-
for (var i of wasmModuleImports) {\n\
398-
print(i + \' : \' + i.kind + \' : \' + i.name + \' : \' + i.module);\n\
399-
varImports.push(i.name);\n\
400-
}\n\
401-
}\n\
402-
catch (e) { print(e) };\n\
403-
/////////////////////////////////////////////////////////////////////////MEMORY\n\
404-
try {\n\
405-
var wasmMemory = wasmInstance.exports.memory;\n\
406-
print(\'[+] wasmMemory.\');\n\
407-
print(wasmMemory);\n\
408-
print(wasmMemory instanceof WebAssembly.Memory);\n\
409-
}\n\
410-
catch (e) { print(e); }\n\
411-
////////////////////////////////////////////////////////////////////////\n\
412-
print(\'[+] End.\');\n";
338+
char WebAssemblyLoadPostfix[] = "]);\
339+
//////////////////////////////////////////////////////////////INIT\
340+
try {\
341+
var wasmModule = new WebAssembly.Module(wasmCode);\
342+
var wasmInstance = new WebAssembly.Instance(wasmModule, importObject);\
343+
\
344+
print('[+] wasmCode validate.');\
345+
print(WebAssembly.validate(wasmCode));\
346+
}\
347+
catch (e) { print(e); }\
348+
////////////////////////////////////////////////////////////EXPORTS\
349+
try {\
350+
var wasmInstanceExported = wasmInstance.exports;\
351+
print('[+] wasmInstanceExported.');\
352+
try {\
353+
var wasmInstanceExportedTable = wasmInstance.exports.table;\
354+
for (var i = 0; i < 100; i++) {\
355+
print(wasmInstanceExportedTable.get(i));\
356+
var f = wasmInstanceExportedTable.get(i);\
357+
try {\
358+
var res = f(i);\
359+
res = f(5.40900887767170327461014974881E-315);\
360+
res = f({});\
361+
}\
362+
catch (e) { print(e); }\
363+
}\
364+
}\
365+
catch (e) { print(e); }\
366+
\
367+
try {\
368+
print(wasmInstanceExported.main(0));\
369+
}\
370+
catch (e) { print(e); }\
371+
\
372+
try {\
373+
for (var i in wasmInstanceExported) {\
374+
try {\
375+
print(eval('wasmInstanceExported.' + i + ';'));\
376+
}\
377+
catch (e) { print(e); }\
378+
try {\
379+
print(eval('wasmInstanceExported.' + i + '(0);'));\
380+
\
381+
}\
382+
catch (e) { print(e); }\
383+
}\
384+
}\
385+
catch (e) { print(e); }\
386+
\
387+
\
388+
var wasmModuleExports = WebAssembly.Module.exports(wasmModule);\
389+
var varExports = [];\
390+
print('[+] wasmModuleExported.')\
391+
for (var i of wasmModuleExports) {\
392+
print(i + ' : ' + i.kind + ' : ' + i.name);\
393+
varExports.push(i.name);\
394+
}\
395+
for (var i of varExports) {\
396+
try {\
397+
print(eval('wasmInstanceExported.' + i + ';'));\
398+
}\
399+
catch (e) { print(e); }\
400+
try {\
401+
print(eval('wasmInstanceExported.' + i + '(0);'));\
402+
}\
403+
catch (e) { print(e); }\
404+
}\
405+
}\
406+
catch (e) { print(e) };\
407+
//////////////////////////////////////////////////////////////IMPORTS\
408+
try {\
409+
var wasmModuleImports = WebAssembly.Module.imports(wasmModule);\
410+
var varImports = [];\
411+
print('[+] wasmModuleImported.');\
412+
for (var i of wasmModuleImports) {\
413+
print(i + ' : ' + i.kind + ' : ' + i.name + ' : ' + i.module);\
414+
varImports.push(i.name);\
415+
}\
416+
for(var scalar of varImports){\
417+
print(scalar);\
418+
}\
419+
}\
420+
catch (e) { print(e) };\
421+
\
422+
///////////////////////////////////////////////////////////////CUSTOM\
423+
try {\
424+
var sections = WebAssembly.Module.customSections(wasmModule, 'custom');\
425+
for(var i in sections){\
426+
print(sections[i]);\
427+
}\
428+
sections = WebAssembly.Module.customSections(wasmModule, 'name');\
429+
for(var i in sections){\
430+
print(sections[i]);\
431+
}\
432+
sections = WebAssembly.Module.customSections(wasmModule, 'unknown');\
433+
for(var i in sections){\
434+
print(sections[i]);\
435+
}\
436+
sections = WebAssembly.Module.customSections(wasmModule, '');\
437+
for(var i in sections){\
438+
print(sections[i]);\
439+
}\
440+
}\
441+
catch (e) { print(e); }\
442+
//////////////////////////////////////////////////////////////END\
443+
print('[+] End.');";
413444

414445
u32 printFlag = 0;
415446

@@ -2594,8 +2625,10 @@ static void write_to_testcase(void* mem, u32 len) {
25942625
JavaScriptWebAssembly[strlen(JavaScriptWebAssembly)] = 0;
25952626

25962627
if(printFlag == 1){
2628+
//SAYF(cGRA "\n\n[GENERATED SAMPLE]\
2629+
//
25972630
SAYF(cGRA "\n\n[GENERATED SAMPLE]\
2598-
\n%s\n" cRST, JavaScriptWebAssembly);
2631+
\n\n" cRST);
25992632
printFlag = 0;
26002633
SAYF(TERM_CLEAR CURSOR_HIDE);
26012634
}
@@ -4118,7 +4151,7 @@ static void show_stats(void) {
41184151

41194152
sprintf(tmp + banner_pad, "%s " cLCY VERSION cLGN
41204153
" (%s)", crash_mode ? cPIN "peruvian were-rabbit" :
4121-
cYEL "american fuzzy lop", use_banner);
4154+
cYEL "afl-wasm by dwfault", use_banner);
41224155

41234156
SAYF("\n%s\n\n", tmp);
41244157

0 commit comments

Comments
 (0)