3/25/2016SQLInjectionCheatSheetbyNetsparkerhttps://www.netsparker.com/blog/websecurity/sqlinjectioncheatsheet/1/13SQLInjectionCheatSheetCategory:WebSecurityReadingsTags:sqlinjection,cheatsheet,websecurityThu,17Mar2016,byFerruhMavitunaWhatisanSQLInjectionCheatSheet?AnSQLinjectioncheatsheetisaresourceinwhichyoucanfinddetailedtechnicalinformationaboutthemanydifferentvariantsoftheSQLInjectionvulnerability.Thischeatsheetisofgoodreferencetobothseasonedpenetrationtesterandalsothosewhoarejustgettingstartedinwebapplicationsecurity.AbouttheSQLInjectionCheatSheetThisSQLinjectioncheatsheetwasoriginallypublishedin2007byFerruhMavitunaonhisblog.WehaveupdateditandmoveditoverfromourCEO'sblog.CurrentlythisSQLCheatSheetonlycontainsinformationforMySQL,MicrosoftSQLServer,andsomelimitedinformationforORACLEandPostgreSQLSQLservers.Someofthesamplesinthissheetmightnotworkineverysituationbecauserealliveenvironmentsmayvarydependingontheusageofparenthesis,differentcodebasesandunexpected,strangeandcomplexSQLsentences.Samplesareprovidedtoallowyoutogetbasicideaofapotentialattackandalmosteverysectionincludesabriefinformationaboutitself.M:MySQLS:SQLServerP:PostgreSQLO:Oracle+:PossiblyallotherdatabasesExamples;(MS)means:MySQLandSQLServeretc.(M*S)means:OnlyinsomeversionsofMySQLorspecialconditionsseerelatednoteandSQLServerTableOfContents1.SyntaxReference,SampleAttacksandDirtySQLInjectionTricks1.LineCommentsSQLInjectionAttackSamples2.InlineCommentsClassicalInlineCommentSQLInjectionAttackSamplesMySQLVersionDetectionSampleAttacks3.StackingQueriesLanguage/DatabaseStackedQuerySupportTableAboutMySQLandPHPStackedSQLInjectionAttackSamples4.IfStatementsMySQLIfStatementSQLServerIfStatementIfStatementSQLInjectionAttackSamplesSUBSCRIBEFollowusNetsparkerWebApplicationSecurityScannerDownloadDemoOnlineScanCaseStudiesNetsparkerDesktopNetsparkerCloudCategoriesWebSecurityReadingsReleasesProductDocs&FAQSNewsEventsSubscribebyEmailGetnotifiedviaemailwhennewblogpostsarepublished.Enteryouremail...ArchiveSelectMonthSearch...
3/25/2016SQLInjectionCheatSheetbyNetsparkerhttps://www.netsparker.com/blog/websecurity/sqlinjectioncheatsheet/2/135.UsingIntegers6.StringOperationsStringConcatenation7.StringswithoutQuotesHexbasedSQLInjectionSamples8.StringModification&Related9.UnionInjectionsUNION–FixingLanguageIssues10.BypassingLoginScreens11.Enablingxp_cmdshellinSQLServer200512.FindingDatabaseStructureinSQLServer13.FastwaytoextractdatafromErrorBasedSQLInjectionsinSQLServer14.BlindSQLInjections15.CoveringYourTracks16.ExtraMySQLNotes17.SecondOrderSQLInjections18.OutofBand(OOB)ChannelAttacksSyntaxReference,SampleAttacksandDirtySQLInjectionTricksEnding/CommentingOut/LineCommentsLineCommentsCommentsoutrestofthequery.Linecommentsaregenerallyusefulforignoringrestofthequerysoyoudon’thavetodealwithfixingthesyntax.‐‐(SM)DROPsampletable;‐‐#(M)DROPsampletable;#LineCommentsSampleSQLInjectionAttacksUsername:admin'‐‐SELECT*FROMmembersWHEREusername='admin'‐‐'ANDpassword='password'Thisisgoingtologyouasadminuser,becauserestoftheSQLquerywillbeignored.InlineCommentsCommentsoutrestofthequerybynotclosingthemoryoucanuseforbypassingblacklisting,removingspaces,obfuscatinganddeterminingdatabaseversions./*CommentHere*/(SM)DROP/*comment*/sampletableDR/**/OP/*bypassblacklisting*/sampletableSELECT/*avoid‐spaces*/password/**/FROM/**/Members/*!MYSQLSpecialSQL*/(M)ThisisaspecialcommentsyntaxforMySQL.It’sperfectfordetectingMySQLversion.Ifyouputacodeintothiscommentsit’sgoingtoexecuteinMySQLonly.Alsoyoucanusethistoexecutesomecodeonlyiftheserverishigherthansuppliedversion.SELECT/*!323021/0,*/1FROMtablenameClassicalInlineCommentSQLInjectionAttackSamplesID:10;DROPTABLEmembers/*Simplygetridofotherstuffattheendtheofquery.Sameas10;DROPTABLEmembers‐‐SELECT/*!323021/0,*/1FROMtablenameWillthrowandivisonby0errorifMySQLversionishigherthan3.23.02