How to SQL Injection! -- Detailed Introduction. « Null Byte :: WonderHowTo

Hello NullByte!This will be my first How To series.In this tutorial you'll learn what SQL is, what SQL injection is and how it benefits you as a hacker.I strongly recommend learning at least the basics of PHP before attempting to learn/use SQL Injection.list of references;SQL WikipediaDVWALearn by trying!PHPTable of Contents:1- What are Databases?2- What is SQL and how does it work?2.1. Defining SQL.2.2. Explaining SQL's usage and Syntax.2.3. SQL's integration in other programming languages.2.4. Conclusion.3- What is SQL Injection?3.1 Defining SQL Injection.3.2 How does SQLi work?4- Final Conclusion.So, let's begin shall we?1. What Are Databases?So what is a Database? Simply put, it's the place where all your data is stored, therefore "Data-Base".Databases are basically a structure of tables, each table containing a set of Rows defining the data and columns containing the data.Image viaanony.wsLet's take this as an example.Be this our table, called "UserData".It contains 3 Rows of data, first being the "ID", second being the "Username" and third being the "Password".This way, we have some data stored for our users.So, let's break it down!Each column here contains a bunch of data specific to one entity (In this case, a user.)For example, the first column in this table contains data that belongs to the user "CyberMask", the second to the user "unicorn".So if I wanted to know CyberMask's password, I'd look for the Row "Password" corresponding the the column where the user is "CyberMask". You could think of it as an an X-axis Y-axis kinda thing.So that's a database, but what does SQL have to do with this?2. What Is SQL and How Does It Work?So what does all that hallahulla has to do with SQL?!This section will contain the following:Defining SQL.Explaining SQL's usage and Syntax.SQL's integration in other programming languages.Conclusion.Defining SQL:SQL is short for Structered-Query-Language, or Sequel as some like to call it.It is a language commonly used for database management.In short, SQL tells databases what to do.Let's say I have a million users in my database and I wanted to get the ID of a specific user, now searching manually would be insane wouldn't it?This is where SQL comes in, I want to tell the database to select the ID of CyberMask and print it out, so how does that work?Explaining SQL's usage and Syntax:Let's take a code snippet as our example:Image viaanony.wsDoes it make sense already?This is called a Query; Queries are simply pieces of code you run.They're different from other languages where each query runs separatly and independently as instructions given to the database through the database engine.So let's break it down!SELECTtells the database to select one or multiple values.IDis the value SELECT is going to select.FROMtells the database what table to use, in this case it'sUserData.WHEREhere is a condition, simply put, it's telling the database to only select ID wherecertainValue=something. In our case, we want the password from the column where the Username Row has the value CyberMask. Makes sense?So now that we've covered SQL's basic usage to retrieve data, let's go further down and explain how websites use it!SQL's integration in other programming languages:So now we know how to fetch data from the database. But how does that relate to websites hacking and other cyber entities?The answer is simple, SQL can be integrated in other languages such as PHP and C# for example.let's take PHP as an example.(PHP is a server-side programming language for web applications)Image viaanony.wsYou see how the syntax is very similiar?It's pretty simple how SQL is integrated in other languages, as for the most part the Query's syntax is almost always the same!So what does that exactly mean? It means that any website that uses a database is most likely using SQL aswell as it's a key ingredient in the database management world.Conclusion:SQL is a powerful language in it's own unique ways. Despite it's simplicity, it's used on a VERY large scale.It can be used on it's own, aswell as integrated into other programming languages.It behaves differently compared to most programming languages, as it runs individually as a set of instructions to the database.Now, we know what SQL is. How does that relate to hacking?Well, let's find out!3. What Is SQL Injection?Defining SQL Injection:SQL Injection is actually just what the name suggests, to inject SQL.No really, it's as simple as that.What you do is inject malicious code in an already existing Query, that way you can manipulate the set of instructions before it's run through the database.SQL Injection at it's best can solely give you full control of the operating system that runs the database. Imagine that.So how does that work?How does SQLi work?We'll only talk theory here for now.Let's take this form as our example:Image viaanony.wsForm runs this query:Image viaanony.wsSo let's break this down.In the php code I assigned a variable called "$username" to that textbox, so anything I type in the textbox will be put in the place of $username inside the query.As a rule of thumb, $username = whatever I type into that textbox.So in theory, if I type a query in that textbox, it should get run.Therefore the "injection" concept.Ofcourse, I would need to type a bit more than a SELECT query, but that's yet to come!4. Final Conclusion:SQL (short for Sequel) is the most used database management language.It's a simple language in the form of instructions called Queries, each instruction (Query) being run individually in real-time through the database.SQL Can be integrated in other programming languages.SQL Injection is the act of squeezing malicious code inside an existing Query.SQL Injection is used in order to gather data/run malicious code on the operating system.It can be a great addition to your skillset as a hacker.That would be all!I hope this becomes a useful contribution to the community!Furthermore, kindly point out anything you would like to see changed/improved/added to this tutorial.Cheers~CM.Want to start making money as a white hat hacker?Jump-start your hacking career with our2020 Premium Ethical Hacking Certification Training Bundlefrom the newNull Byte Shopand get over 60 hours of training from cybersecurity professionals.Buy Now (90% off) >Other worthwhile deals to check out:97% off The Ultimate 2021 White Hat Hacker Certification Bundle99% off The 2021 All-in-One Data Scientist Mega Bundle98% off The 2021 Premium Learn To Code Certification Bundle62% off MindMaster Mind Mapping Software: Perpetual LicenseRelatedSQL Injection 101:How to Fingerprint Databases & Perform General Reconnaissance for a More Successful AttackSQL Injection 101:Advanced Techniques for Maximum ExploitationSQL Injection 101:Database & SQL Basics Every Hacker Needs to KnowHow To:SQL Injection Finding Vulnerable Websites..SQL Injection 101:How to Avoid Detection & Bypass DefensesBecome an Elite Hacker Part 4:Hacking a Website. [Part 1]How To:Use SQL Injection to Run OS Commands & Get a ShellSQL Injection 101:Common Defense Methods Hackers Should Be Aware OfHow To:Compromise a Web Server & Upload Files to Check for Privilege Escalation, Part 1How To:Hack websites with SQL injectionHow To:Protect against SQL injection attacks when programming in PHPHow to Hack Databases:The Terms & Technologies You Need to Know Before Getting StartedHow To:Hack Hackademic.RTB1 Machine Part 1How To:The Essential Newbie's Guide to SQL Injections and Manipulating Data in a MySQL DatabaseHow To:Spider Web Pages with Nmap for SQLi VulnerabilitiesGoodnight Byte:HackThisSite, Realistic 4 - Real Hacking SimulationsGoogle Dorking:AmIDoinItRite?How To:Hack websites with SQL injection and WebGoatHow To:Is Your Website Vulnerable to XSS Injections? Here's How to Protect Your VisitorsHow To:Protect Your PHP Website from SQL Injection HacksNews:Hardvard.edu Remote SQL 0day