????λ?????????? >> ??????????
Nmap??????????????棩
?????AspirationFlow ???????[ 2017/1/5 10:40:36 ] ?????????????????? Nmap
??????????????
??????н??????????nmap_main()?е???script_scan()??????
?????????script_scan()?????????????????????????????η????main()??????????nse_main.lua????е?main???У???????н????????????????
????main()???????????????????????裺???裨SCRIPT_PRE_SCAN?????????裨SCRIPT_SCAN????????裨SCRIPT_POST_SCAN???????輴??Nmap???????棨??н??????????????????????????е?????裬???????????????????????????????絽?????????????????DNS????????????裬?????NSE???????????????????????????跽???????裬?????????????????Щ??????????????????????Щ??衣
??????NSE????ж????崥??????rule??????????????????????иy????NSE????4?й???prerule()????????????ù????????????θy??????У?hostrule(host)?ù?????????????????????У?port(host??port)???????????????????????У????????????????????????postrule()?????????????????????????С?
??????main()?????к????????run??????????run()?????????????????????????????????????????????????????????????????????????????
????run()????????????????У???ж??У?Running Queue??????????У?Waiting Queue??????????У?Pending Queue?????????????????????????л??????????????????????????
????3????????
///L_NSE???????Lua???????
staticlua_State*L_NSE=NULL;
///open_nse???????Lua???????Lua??????????
///????init_main()?????????????
voidopen_nse(void)
{
if(L_NSE==NULL)///?????????Lua??
{
/*
Settherandomseedvalueonbehalfofscripts.SinceLuausesthe
Crandandsrandfunctions??whichhaveastaticseedfortheentire
program??wedon'twantscriptsdoingthisthemselves.
*/
srand(get_random_uint());
///????Lua?????????????????Lua????????
if((L_NSE=luaL_newstate())==NULL)
fatal("%s:failedtoopenaLuastate!"??SCRIPT_ENGINE);
lua_atpanic(L_NSE??panic);///????????????????????panic????
#if0
/*Lua5.2*/
lua_pushcfunction(L_NSE??init_main);
lua_pushlightuserdata(L_NSE??&o.chosenScripts);
if(lua_pcall(L_NSE??1??0??0))
#else
///???lua_cpcall()??????????C???????init_main()
if(lua_cpcall(L_NSE??init_main??&o.chosenScripts))
#endif
fatal("%s:failedtoinitializethescriptengine:n%sn"??SCRIPT_ENGINE??
lua_tostring(L_NSE??-1));
}
}
///scipt_scan??????????н?????????
///???????????????run_main()??????о????????????
voidscript_scan(std::vector<Target*>&targets??stypescantype)
{
///???????????????????????????SCRIPT_PRE_SCAN/SCRIPT_SCAN/SCRIPT_POST_SCAN??
o.current_scantype=scantype;
///????L_NSE??????????????C??Lua???y???????????????????
assert(L_NSE!=NULL);
lua_settop(L_NSE??0);/*clearthestack*/
#if0
/*Lua5.2*/
lua_pushcfunction(L_NSE??run_main);
lua_pushlightuserdata(L_NSE??&targets);
if(lua_pcall(L_NSE??1??0??0))
#else
///???lua_cpcall()??????????C???????run_main()
if(lua_cpcall(L_NSE??run_main??&targets))
#endif
error("%s:ScriptEngineScanAborted.nAnerrorwasthrownbythe"
"engine:%s"??SCRIPT_ENGINE??lua_tostring(L_NSE??-1));
}
voidclose_nse(void)
{
///???Lua??
if(L_NSE!=NULL)
{
lua_close(L_NSE);
L_NSE=NULL;
}
}
staticintinit_main(lua_State*L)
{
charpath[MAXPATHLEN];
std::vector<std::string>*rules=(std::vector<std::string>*)
lua_touserdata(L??1);
/*Loadsomebasiclibraries*/
luaL_openlibs(L);///????Lua??????
set_nmap_libraries(L);///????Nmap?????Lua??
lua_newtable(L);
lua_setfield(L??LUA_REGISTRYINDEX??NSE_CURRENT_HOSTS);
/*Loaddebug.tracebackforcollectinganyerrortracebacks*/
lua_settop(L??0);/*clearthestack*/
lua_getglobal(L??"debug");
lua_getfield(L??-1??"traceback");
lua_replace(L??1);//debug.tracebackstackposition1
lua_pushvalue(L??1);
lua_setfield(L??LUA_REGISTRYINDEX??NSE_TRACEBACK);/*savecopy*/
/*LoadmainLuacode??stackposition2*/
///??nse_main.lua?????????????????????????????????????2????????????lua_pcall()???????
if(nmap_fetchfile(path??sizeof(path)??"nse_main.lua")!=1)
luaL_error(L??"couldnotlocatense_main.lua");
if(luaL_loadfile(L??path)!=0)
luaL_error(L??"couldnotloadnse_main.lua:%s"??lua_tostring(L??-1));
/*ThefirstargumenttotheNSEMainLuacodeistheprivatense
*librarytablewhichexposescertainnecessaryCfunctionsto
*theLuaengine.
*/
///????????nse_main.lua?????C????????????????3??
open_cnse(L);//stackindex3
/*Thesecondargumentisthescriptrules??includingthe
*files/directories/categoriespassedastheuserdatatothisfunction.
*/
///??????????????????????????????4??
lua_createtable(L??rules->size()??0);//stackindex4
for(std::vector<std::string>::iteratorsi=rules->begin();
si!=rules->end();si++)
{
lua_pushstring(L??si->c_str());
lua_rawseti(L??4??lua_objlen(L??4)+1);
}
/*GetLuamainfunction*/
///??????nse_main.lua?????????????????????2????
///????2?????????????3/4???????1????????????????????????
///??????????????????????1????debug.traceback????
///???????nse_main.lua???????????????е????????????Script/Thread??
if(lua_pcall(L??2??1??1)!=0)lua_error(L);/*wewantedatraceback*/
///?????nse_main.lua?????????nse_main.lua?е?main?????????????????У?
///???????????????????????main??????
lua_setfield(L??LUA_REGISTRYINDEX??NSE_MAIN);
return0;
}
staticintrun_main(lua_State*L)
{
std::vector<Target*>*targets=(std::vector<Target*>*)
lua_touserdata(L??1);
lua_settop(L??0);///??????
/*Newhostgroup*/
lua_newtable(L);///???????????
lua_setfield(L??LUA_REGISTRYINDEX??NSE_CURRENT_HOSTS);
///????errortraceback????
lua_getfield(L??LUA_REGISTRYINDEX??NSE_TRACEBACK);/*index1*/
///???nse_main.lua?е?main()????
lua_getfield(L??LUA_REGISTRYINDEX??NSE_MAIN);/*index2*/
assert(lua_isfunction(L??-1));///??????????????????д?
/*Thefirstandonlyargumenttomainisthelistoftargets.
*Thishasallthetargetnames??1-N??inalist.
*/
///main(hosts??scantype)
///main???????????????????????????????????????PRE/SCRIPT/POST??
///???′?????μ??????????????NSE_CURRENT_HOSTS????
lua_createtable(L??targets->size()??0);//stackindex3
lua_getfield(L??LUA_REGISTRYINDEX??NSE_CURRENT_HOSTS);/*index4*/
for(std::vector<Target*>::iteratorti=targets->begin();
ti!=targets->end();ti++)
{
Target*target=(Target*)*ti;
constchar*TargetName=target->TargetName();
constchar*targetipstr=target->targetipstr();
lua_newtable(L);
set_hostinfo(L??target);
lua_rawseti(L??3??lua_objlen(L??3)+1);
if(TargetName!=NULL&&strcmp(TargetName??"")!=0)
lua_pushstring(L??TargetName);
else
lua_pushstring(L??targetipstr);
lua_pushlightuserdata(L??target);
lua_rawset(L??4);/*addtoNSE_CURRENT_HOSTS*/
}
lua_pop(L??1);/*popNSE_CURRENT_HOSTS*/
///????main()??????????????????
/*pushscriptscantypephase*/
switch(o.current_scantype)
{
caseSCRIPT_PRE_SCAN:
lua_pushstring(L??NSE_PRE_SCAN);
break;
caseSCRIPT_SCAN:
lua_pushstring(L??NSE_SCAN);
break;
caseSCRIPT_POST_SCAN:
lua_pushstring(L??NSE_POST_SCAN);
break;
default:
fatal("%s:failedtosetthescriptscanphase.n"??SCRIPT_ENGINE);
}
///???????????main()????????????????0?????????????????????????index1λ??
if(lua_pcall(L??2??0??1)!=0)lua_error(L);/*wewantedatraceback*/
return0;
}
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????
??????
Nmap????ò???????л??°???msf??nmap??????????Nmap?????????????Linux???????????nmap?????Python-Nmap??ü???????????Nmap????????LazyMap????Nmap??貢??????Python????Nmap???????Nmap????????????Nmap????????????????????Nmap???????kali?????????????????nmap?????Nmap????????&????????Nmap???????optionPython????Nmap??????????????????xmlPython????-Nmap???IP??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11????????
?????????App Bug???????????????????????Jmeter?????????QC??????APP????????????????app?????е????????jenkins+testng+ant+webdriver??????????????JMeter????HTTP???????Selenium 2.0 WebDriver ??????