Linux - SecurityThis forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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.'"
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!
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> !!
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.
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.
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.
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.