LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 03-14-2016, 04:40 PM   #1
akalinin
Member
 
Registered: Apr 2014
Location: Michigan
Distribution: slackware
Posts: 31

Rep: Reputation: Disabled
Is this a code injection attack via my website?


Hello,
I run a small, simple website on Slackware 14.1 & apache 2.4. I wrote it with Vim, and there is no PHP or other dynamic content.

Since making the web site accessable to the public a week ago, I'm getting the following attacks when checking my access_log. What on earth is this?

202.109.143.16 - - [14/Mar/2016:07:07:20 -0400] "POST /cgi-bin/php5?%2D%64+%61%6C%6C%6F%77%5F%75%72%6C%5F%69%6E%63%6C%75%64%65%3D%6F%6E+%2D%64+%73%61%66%65%5F%6D%6 F%64%65%3D%6F%66%66+%2D%64+%73%75%68%6F%73%69%6E%2E%73%69%6D%75%6C%61%74%69%6F%6E%3D%6F%6E+%2D%64+%6 4%69%73%61%62%6C%65%5F%66%75%6E%63%74%69%6F%6E%73%3D%22%22+%2D%64+%6F%70%65%6E%5F%62%61%73%65%64%69% 72%3D%6E%6F%6E%65+%2D%64+%61%75%74%6F%5F%70%72%65%70%65%6E%64%5F%66%69%6C%65%3D%70%68%70%3A%2F%2F%69 %6E%70%75%74+%2D%64+%63%67%69%2E%66%6F%72%63%65%5F%72%65%64%69%72%65%63%74%3D%30+%2D%64+%63%67%69%2E %72%65%64%69%72%65%63%74%5F%73%74%61%74%75%73%5F%65%6E%76%3D%30+%2D%6E HTTP/1.1" 404 210

202.109.143.16 - - [14/Mar/2016:07:07:21 -0400] "POST /cgi-bin/php.cgi?%2D%64+%61%6C%6C%6F%77%5F%75%72%6C%5F%69%6E%63%6C%75%64%65%3D%6F%6E+%2D%64+%73%61%66%65%5F%6 D%6F%64%65%3D%6F%66%66+%2D%64+%73%75%68%6F%73%69%6E%2E%73%69%6D%75%6C%61%74%69%6F%6E%3D%6F%6E+%2D%64 +%64%69%73%61%62%6C%65%5F%66%75%6E%63%74%69%6F%6E%73%3D%22%22+%2D%64+%6F%70%65%6E%5F%62%61%73%65%64% 69%72%3D%6E%6F%6E%65+%2D%64+%61%75%74%6F%5F%70%72%65%70%65%6E%64%5F%66%69%6C%65%3D%70%68%70%3A%2F%2F %69%6E%70%75%74+%2D%64+%63%67%69%2E%66%6F%72%63%65%5F%72%65%64%69%72%65%63%74%3D%30+%2D%64+%63%67%69 %2E%72%65%64%69%72%65%63%74%5F%73%74%61%74%75%73%5F%65%6E%76%3D%30+%2D%6E HTTP/1.1" 404 213

202.109.143.16 - - [14/Mar/2016:07:07:22 -0400] "POST /cgi-bin/php-cgi?%2D%64+%61%6C%6C%6F%77%5F%75%72%6C%5F%69%6E%63%6C%75%64%65%3D%6F%6E+%2D%64+%73%61%66%65%5F%6D%6F %64%65%3D%6F%66%66+%2D%64+%73%75%68%6F%73%69%6E%2E%73%69%6D%75%6C%61%74%69%6F%6E%3D%6F%6E+%2D%64+%64 %69%73%61%62%6C%65%5F%66%75%6E%63%74%69%6F%6E%73%3D%22%22+%2D%64+%6F%70%65%6E%5F%62%61%73%65%64%69%7 2%3D%6E%6F%6E%65+%2D%64+%61%75%74%6F%5F%70%72%65%70%65%6E%64%5F%66%69%6C%65%3D%70%68%70%3A%2F%2F%69% 6E%70%75%74+%2D%64+%63%67%69%2E%66%6F%72%63%65%5F%72%65%64%69%72%65%63%74%3D%30+%2D%64+%63%67%69%2E% 72%65%64%69%72%65%63%74%5F%73%74%61%74%75%73%5F%65%6E%76%3D%30+%2D%6E HTTP/1.1" 404 213

202.109.143.16 - - [14/Mar/2016:07:07:22 -0400] "POST /cgi-bin/php?%2D%64+%61%6C%6C%6F%77%5F%75%72%6C%5F%69%6E%63%6C%75%64%65%3D%6F%6E+%2D%64+%73%61%66%65%5F%6D%6F %64%65%3D%6F%66%66+%2D%64+%73%75%68%6F%73%69%6E%2E%73%69%6D%75%6C%61%74%69%6F%6E%3D%6F%6E+%2D%64+%64 %69%73%61%62%6C%65%5F%66%75%6E%63%74%69%6F%6E%73%3D%22%22+%2D%64+%6F%70%65%6E%5F%62%61%73%65%64%69%7 2%3D%6E%6F%6E%65+%2D%64+%61%75%74%6F%5F%70%72%65%70%65%6E%64%5F%66%69%6C%65%3D%70%68%70%3A%2F%2F%69% 6E%70%75%74+%2D%64+%63%67%69%2E%66%6F%72%63%65%5F%72%65%64%69%72%65%63%74%3D%30+%2D%64+%63%67%69%2E% 72%65%64%69%72%65%63%74%5F%73%74%61%74%75%73%5F%65%6E%76%3D%30+%2D%6E HTTP/1.1" 404 209

202.109.143.16 - - [14/Mar/2016:07:07:23 -0400] "POST /cgi-bin/php4?%2D%64+%61%6C%6C%6F%77%5F%75%72%6C%5F%69%6E%63%6C%75%64%65%3D%6F%6E+%2D%64+%73%61%66%65%5F%6D%6 F%64%65%3D%6F%66%66+%2D%64+%73%75%68%6F%73%69%6E%2E%73%69%6D%75%6C%61%74%69%6F%6E%3D%6F%6E+%2D%64+%6 4%69%73%61%62%6C%65%5F%66%75%6E%63%74%69%6F%6E%73%3D%22%22+%2D%64+%6F%70%65%6E%5F%62%61%73%65%64%69% 72%3D%6E%6F%6E%65+%2D%64+%61%75%74%6F%5F%70%72%65%70%65%6E%64%5F%66%69%6C%65%3D%70%68%70%3A%2F%2F%69 %6E%70%75%74+%2D%64+%63%67%69%2E%66%6F%72%63%65%5F%72%65%64%69%72%65%63%74%3D%30+%2D%64+%63%67%69%2E %72%65%64%69%72%65%63%74%5F%73%74%61%74%75%73%5F%65%6E%76%3D%30+%2D%6E HTTP/1.1" 404 210
 
Old 03-14-2016, 04:48 PM   #2
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
China hacking.
 
Old 03-14-2016, 05:14 PM   #3
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,153

Rep: Reputation: 1265Reputation: 1265Reputation: 1265Reputation: 1265Reputation: 1265Reputation: 1265Reputation: 1265Reputation: 1265Reputation: 1265
Looks like this common scan for a vulnerability

http://security.stackexchange.com/qu...exploit-attack
 
Old 03-14-2016, 05:47 PM   #4
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,679
Blog Entries: 4

Rep: Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947
The attacker is hoping that you have a PHP interpreter within a directory that can be accessed by the alias "/cgi-bin/" on your website, and is attempting to "stuff PHP source code" into it while concealing (superficially ...) what he is up to. The "%xx" symbols correspond to ASCII characters.
 
Old 03-14-2016, 07:52 PM   #5
akalinin
Member
 
Registered: Apr 2014
Location: Michigan
Distribution: slackware
Posts: 31

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by sundialsvcs View Post
The attacker is hoping that you have a PHP interpreter within a directory that can be accessed by the alias "/cgi-bin/" on your website, and is attempting to "stuff PHP source code" into it while concealing (superficially ...) what he is up to. The "%xx" symbols correspond to ASCII characters.
I take it (by the 404 error code returned to each attempt) that this was unsuccessful. Thanks to all the respondents, I now understand what is going on here.
 
Old 03-14-2016, 09:15 PM   #6
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,679
Blog Entries: 4

Rep: Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947
Indeed, the attacker is hoping that you are ... shall we say ... "unaware."

That your Apache configuration had an Alias '/cgi-bin/' ... directive with not the slightest knowledge of its implications, nor of what it might be pointing to.

How do I say it politely? ... "If you do not know what you are doing, nor what you have done, then: 'I have a script for that.'"
 
Old 03-14-2016, 09:55 PM   #7
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,249

Rep: Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323
This is my attempt to decode the URLs:

Code:
/cgi-bin/php5?-d+allow_url_include=on+-d+safe_m%6 Fde=off+-d+suhosin.simulation=on+-d+%6 4isable_functions=""+-d+open_basedi% 72=none+-d+auto_prepend_file=php://i nput+-d+cgi.force_redirect=0+-d+cgi. redirect_status_env=0+-n

/cgi-bin/php.cgi?-d+allow_url_include=on+-d+safe_%6 Dode=off+-d+suhosin.simulation=on+-d +disable_functions=""+-d+open_based% 69r=none+-d+auto_prepend_file=php:// input+-d+cgi.force_redirect=0+-d+cgi .redirect_status_env=0+-n

/cgi-bin/php-cgi?-d+allow_url_include=on+-d+safe_mo de=off+-d+suhosin.simulation=on+-d+d isable_functions=""+-d+open_basedi%7 2=none+-d+auto_prepend_file=php://i% 6Eput+-d+cgi.force_redirect=0+-d+cgi.% 72edirect_status_env=0+-n

/cgi-bin/php?-d+allow_url_include=on+-d+safe_mo de=off+-d+suhosin.simulation=on+-d+d isable_functions=""+-d+open_basedi%7 2=none+-d+auto_prepend_file=php://i% 6Eput+-d+cgi.force_redirect=0+-d+cgi.% 72edirect_status_env=0+-n

/cgi-bin/php4?-d+allow_url_include=on+-d+safe_m%6 Fde=off+-d+suhosin.simulation=on+-d+%6 4isable_functions=""+-d+open_basedi% 72=none+-d+auto_prepend_file=php://i nput+-d+cgi.force_redirect=0+-d+cgi. redirect_status_env=0+-n
Which is consistent with smallpond's information.

Last edited by dugan; 03-14-2016 at 10:15 PM.
 
Old 03-14-2016, 10:21 PM   #8
akalinin
Member
 
Registered: Apr 2014
Location: Michigan
Distribution: slackware
Posts: 31

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by sundialsvcs View Post
Indeed, the attacker is hoping that you are ... shall we say ... "unaware."

That your Apache configuration had an Alias '/cgi-bin/' ... directive with not the slightest knowledge of its implications, nor of what it might be pointing to.

How do I say it politely? ... "If you do not know what you are doing, nor what you have done, then: 'I have a script for that.'"
My httpd.conf does contain 'ScriptAlias /cgi-bin/ "/srv/httpd/cgi-bin/"'. I'll comment that out since I have nothing of value in the cgi-bin directory anyway. Thanks for the advice!
 
Old 03-16-2016, 03:30 PM   #9
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,679
Blog Entries: 4

Rep: Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947
Yes, you should always remove from the configuration anything that's "there by default." If you don't have CGI programs in a site, then there's zero reason for it to have any CGI-enabled locations. (And if you do, why call it something as obvious as "cgi-bin?" Why not call it, say, "footballs?")

Pay particular attention to the default <VirtualHost> !!
 
Old 03-17-2016, 12:39 AM   #10
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 2,163

Rep: Reputation: 449Reputation: 449Reputation: 449Reputation: 449Reputation: 449
In any input text box or other forms, to prevent injection attack. Perform keys filtering on those input boxes that only letters and numbers are allowed. No matter how the inject like the one you posted above which has back slash, percent and plus sign those will be rejected.
 
Old 03-17-2016, 07:18 AM   #11
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,679
Blog Entries: 4

Rep: Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947
Futhermore, when issuing SQL queries, use bound parameters! (Early PHP's could not do this, but "mysqli" can.)

Instead of textually constructing an SQL query string such as "SELECT * FROM PRODUCTS WHERE PRODUCT_ID = 'foo'; DROP TABLE PRODUCTS;" ... ... code the query a "SELECT * FROM PRODUCTS WHERE PRODUCT_ID = ?" (notice that the question-mark is not quoted ...). Then, bind the user's input to the first parameter, and execute the query.

SQL will promptly realize that "'foo;' DROP TABLE PRODUCTS;" is not a valid product-id.

It now becomes impossible to "inject SQL," because the SQL strings that are to be executed are now fixed, and the user's inputs are used only as parameters to them. Furthermore, such a query can be "prepared" one time and then re-executed multiple times with different sets of parameters.

Last edited by sundialsvcs; 03-17-2016 at 07:21 AM.
 
1 members found this post helpful.
Old 03-21-2016, 05:04 AM   #12
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 2,163

Rep: Reputation: 449Reputation: 449Reputation: 449Reputation: 449Reputation: 449
Question

Quote:
Originally Posted by sundialsvcs View Post
Futhermore, when issuing SQL queries, use bound parameters! (Early PHP's could not do this, but "mysqli" can.)

Instead of textually constructing an SQL query string such as "SELECT * FROM PRODUCTS WHERE PRODUCT_ID = 'foo'; DROP TABLE PRODUCTS;" ... ... code the query a "SELECT * FROM PRODUCTS WHERE PRODUCT_ID = ?" (notice that the question-mark is not quoted ...). Then, bind the user's input to the first parameter, and execute the query.

SQL will promptly realize that "'foo;' DROP TABLE PRODUCTS;" is not a valid product-id.

It now becomes impossible to "inject SQL," because the SQL strings that are to be executed are now fixed, and the user's inputs are used only as parameters to them. Furthermore, such a query can be "prepared" one time and then re-executed multiple times with different sets of parameters.
Hi sundialsvcs, found your post quite interesting.

So this one is a valid query: "SELECT * FROM PRODUCTS WHERE PRODUCT_ID = ?"

But how to bind the query to that statement, to replace "?".

Sorry but i'm not familiar with this thing but you have an excellent idea.
 
Old 03-21-2016, 07:32 AM   #13
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,679
Blog Entries: 4

Rep: Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947
If you look at the API calls for PHP's "mysqli" interface, you'll find functions to "bind parameters," as well as to bind outputs.

http://php.net/manual/en/mysqli-stmt.bind-param.php

http://php.net/manual/en/mysqli-stmt.bind-result.php

Other languages have had this concept for a very long time, and make it very easy to do. (For instance, Perl's "DBI" interface unit allows you to supply an array of parameter values in the "usual" call for making a query.)

Basically, what happens is that when SQL "prepares" the query, to create a so-called "execution plan," the plan says that the query is to have certain parameters which must be supplied (separately ...) each time the query runs. These parameters are not part of the SQL text. Different parameter-sets can be supplied as the same prepared statement-handle is executed an arbitrary number of times.
 
1 members found this post helpful.
Old 03-21-2016, 08:13 PM   #14
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 2,163

Rep: Reputation: 449Reputation: 449Reputation: 449Reputation: 449Reputation: 449
Thanks for the link.

$stmt = mysqli_prepare($link, "INSERT INTO CountryLanguage VALUES (?, ?, ?, ?)");

mysqli_stmt_bind_param($stmt, 'sssd', $code, $language, $official, $percent);

so basically, if there is an injection and it doesn't match the string type which is the 'sssd' and doesn't match also the prepared parameters. Injection will not be possible since the parameters bind are fixed.

Hope I understand it correctly, Thank you, Sundialsvcs.
 
Old 03-22-2016, 08:16 AM   #15
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,679
Blog Entries: 4

Rep: Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947
Exactly so. "The SQL statement that is to be executed" is found only in supplied string, which does not have any user-provided content. This statement, in the example above, has four input-parameters which must be supplied with values each time the prepared statement-handle ($stmt ...) is executed. Different parameter values may be provided each time $stmt is executed: there is no need to re-prepare the handle. Even if the parameter values "look like SQL," they are interpreted only as character-strings (or whatever data-type you said they were ...). In other words, they are input data to the query; never a part of the query itself.

This is not only more secure, but also more efficient. The SQL engine parses the SQL and prepares the "execution plan," as represented by the statement-handle, only one time. And, if you happen to be executing a statement millions of times, that does make a measurable difference.

It utterly baffles me why PHP did not provide easy access to this facility from the very start. (And why, when they finally did add it, they did not make it "easy.") It has always been available.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Injection attack against my server sneakyimp Linux - Security 22 12-10-2015 08:03 AM
False data injection Attack in ns-BGP newinubuntu Linux - Networking 0 02-14-2015 09:44 AM
LXer: Bash susceptible to environment variables code injection attack LXer Syndicated Linux News 0 09-25-2014 12:10 PM
Clean up begins after massive website attack Jeebizz Linux - News 0 04-04-2011 10:05 AM
Vulnerability in website with sql Injection tanveer Linux - Security 7 03-28-2009 08:28 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 07:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration