Is there a way to see if database has been accessed through SQL Injection attack?How to protect MySQL...

Confusion about different running times of two algorithms in C

Can I legally make a website about boycotting a certain company?

Calculating total "on row" bytes for each row ... the easy way

Was the Soviet N1 really capable of sending 9.6 GB/s of telemetry?

Ramanujan's radical and how we define an infinite nested radical

Buying a "Used" Router

Why would you use 2 alternate layout buttons instead of 1, when only one can be selected at once

Can you wish for more wishes from an Efreeti bound to service via an Efreeti Bottle?

What does an unprocessed RAW file look like?

How can guns be countered by melee combat without raw-ability or exceptional explanations?

Exploding Numbers

Multiple null checks in Java 8

How can a kingdom keep the secret of a missing monarch from the public?

How to achieve physical gender equality?

Coworker is trying to get me to sign his petition to run for office. How to decline politely?

How to typeset a small black square as a binary operator?

How do I know my password or backup information is not being shared when creating a new wallet?

Why write a book when there's a movie in my head?

Translation for threshold (figuratively)

Why are "square law" devices important?

What if you do not believe in the project benefits?

Is it common to refer to someone as "Prof. Dr. [LastName]"?

How do I add a strong "onion flavor" to the biryani (in restaurant style)?

Coworker asking me to not bring cakes due to self control issue. What should I do?



Is there a way to see if database has been accessed through SQL Injection attack?


How to protect MySQL database from sql-injection?intermittent MySQL crashes with error “Fatal error: cannot allocate memory for the buffer pool”“Site Offline” MySQL server failing to start and stopMySQL with slow queriesIs it safe to run optimze on mutliple tables in parallel in mysql (percona)Bringing SQL Server filegroups onlineHost not Allowed Connectivity to MySQL ServerMySQL running out of memoryMicrosoft SQL Server SQL Injection Through .NET Even With Quote EscapingTable creation on Ubuntu insanely slow?













1















I recently discovered that my website had a page with a SQL Injection vulnerability. Upon testing, it was easily exploitable with a pentesting tool like sqlmap. How do I figure out if the site database has been accessed with a SQL Injection attack, possibly exploiting this loophole? The server is running Apache/2.4.18 and MySQL Ver 14.14 Distrib 5.7.16.










share|improve this question














bumped to the homepage by Community 6 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.











  • 1





    Are you logging all queries? (check stackoverflow.com/questions/303994/log-all-queries-in-mysql/…) If so... check your log for "strange" or "unusual" queries...

    – joanolo
    Jun 4 '17 at 16:06






  • 1





    I am logging all queries. Is there any way to map the queries to the IP addresses from which they came? I want to blacklist these IPs.

    – delphin
    Jun 4 '17 at 16:15








  • 1





    I don't think you can by only looking at the database log, the database is not accessed from those IPs, but from your web server. The logs of your web server might point you in the right direction. But take into account that any rogue actor might be using (probably through zombie computers) very many IP addresses.

    – joanolo
    Jun 4 '17 at 17:54


















1















I recently discovered that my website had a page with a SQL Injection vulnerability. Upon testing, it was easily exploitable with a pentesting tool like sqlmap. How do I figure out if the site database has been accessed with a SQL Injection attack, possibly exploiting this loophole? The server is running Apache/2.4.18 and MySQL Ver 14.14 Distrib 5.7.16.










share|improve this question














bumped to the homepage by Community 6 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.











  • 1





    Are you logging all queries? (check stackoverflow.com/questions/303994/log-all-queries-in-mysql/…) If so... check your log for "strange" or "unusual" queries...

    – joanolo
    Jun 4 '17 at 16:06






  • 1





    I am logging all queries. Is there any way to map the queries to the IP addresses from which they came? I want to blacklist these IPs.

    – delphin
    Jun 4 '17 at 16:15








  • 1





    I don't think you can by only looking at the database log, the database is not accessed from those IPs, but from your web server. The logs of your web server might point you in the right direction. But take into account that any rogue actor might be using (probably through zombie computers) very many IP addresses.

    – joanolo
    Jun 4 '17 at 17:54
















1












1








1


1






I recently discovered that my website had a page with a SQL Injection vulnerability. Upon testing, it was easily exploitable with a pentesting tool like sqlmap. How do I figure out if the site database has been accessed with a SQL Injection attack, possibly exploiting this loophole? The server is running Apache/2.4.18 and MySQL Ver 14.14 Distrib 5.7.16.










share|improve this question














I recently discovered that my website had a page with a SQL Injection vulnerability. Upon testing, it was easily exploitable with a pentesting tool like sqlmap. How do I figure out if the site database has been accessed with a SQL Injection attack, possibly exploiting this loophole? The server is running Apache/2.4.18 and MySQL Ver 14.14 Distrib 5.7.16.







mysql sql-injection






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jun 4 '17 at 15:57









delphindelphin

61




61





bumped to the homepage by Community 6 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 6 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.










  • 1





    Are you logging all queries? (check stackoverflow.com/questions/303994/log-all-queries-in-mysql/…) If so... check your log for "strange" or "unusual" queries...

    – joanolo
    Jun 4 '17 at 16:06






  • 1





    I am logging all queries. Is there any way to map the queries to the IP addresses from which they came? I want to blacklist these IPs.

    – delphin
    Jun 4 '17 at 16:15








  • 1





    I don't think you can by only looking at the database log, the database is not accessed from those IPs, but from your web server. The logs of your web server might point you in the right direction. But take into account that any rogue actor might be using (probably through zombie computers) very many IP addresses.

    – joanolo
    Jun 4 '17 at 17:54
















  • 1





    Are you logging all queries? (check stackoverflow.com/questions/303994/log-all-queries-in-mysql/…) If so... check your log for "strange" or "unusual" queries...

    – joanolo
    Jun 4 '17 at 16:06






  • 1





    I am logging all queries. Is there any way to map the queries to the IP addresses from which they came? I want to blacklist these IPs.

    – delphin
    Jun 4 '17 at 16:15








  • 1





    I don't think you can by only looking at the database log, the database is not accessed from those IPs, but from your web server. The logs of your web server might point you in the right direction. But take into account that any rogue actor might be using (probably through zombie computers) very many IP addresses.

    – joanolo
    Jun 4 '17 at 17:54










1




1





Are you logging all queries? (check stackoverflow.com/questions/303994/log-all-queries-in-mysql/…) If so... check your log for "strange" or "unusual" queries...

– joanolo
Jun 4 '17 at 16:06





Are you logging all queries? (check stackoverflow.com/questions/303994/log-all-queries-in-mysql/…) If so... check your log for "strange" or "unusual" queries...

– joanolo
Jun 4 '17 at 16:06




1




1





I am logging all queries. Is there any way to map the queries to the IP addresses from which they came? I want to blacklist these IPs.

– delphin
Jun 4 '17 at 16:15







I am logging all queries. Is there any way to map the queries to the IP addresses from which they came? I want to blacklist these IPs.

– delphin
Jun 4 '17 at 16:15






1




1





I don't think you can by only looking at the database log, the database is not accessed from those IPs, but from your web server. The logs of your web server might point you in the right direction. But take into account that any rogue actor might be using (probably through zombie computers) very many IP addresses.

– joanolo
Jun 4 '17 at 17:54







I don't think you can by only looking at the database log, the database is not accessed from those IPs, but from your web server. The logs of your web server might point you in the right direction. But take into account that any rogue actor might be using (probably through zombie computers) very many IP addresses.

– joanolo
Jun 4 '17 at 17:54












3 Answers
3






active

oldest

votes


















0














To be pro-active you may have your application to use PDO instead of plain SQL query.



Measures to detect SQL Injections could be :




  1. Alert if any query running beyond X secs or any breaching value to relevant teams.


  2. The team could see if slow query log / show processlist contains unusual entries, if confirmed as SQL injection kill the query and remove that application user as a preventive measure.







share|improve this answer































    0














    See Apache's access.log. Interesting things show up there.






    share|improve this answer































      0














      Since you log all queries against the database, look for queries that don't belong.



      Start with queries that failed. Assuming your app isn't riddle with bugs, there should be very few queries submitted to the DB that fail. Attackers typically have a set of queries they execute once they find a vulnerable app. If you apply the principle of least privileges on accounts used to access the DB, you should find a bunch of failed queries. There will also be queries that fail because a less sophisticated attacker might have a bunch of queries that are not compatible with your database edition, version or vendor.



      Next, look for queries/commands that could not have been generated by your application. For instance, if the application should never accesses system tables, system functions, information schema, etc... but you see them in your log, that's a good indicator something might be amiss and warrants deeper investigation. Looking at your OS logs might be helpful here in case they tried or succeeded in planting a backdoor/rootkit.



      Once you're done with that, look for queries with unusual/unexpected behavior. For instance, queries that return significantly more data than normal. If you see queries that access all tables around the same time or ran show tables then accessed each table in order, there's a good chance you have an attacker that tried (or succeeded) to exfiltrate data. Even something seemingly innocuous like SELECT * without a WHERE clause is suspicious (assuming your app doesn't do this). Note that this applies to any possible query, not just SELECT. The attacker might be some disgruntled employee and decided to randomly DELETE or UPDATE data to get you in trouble with your auditors or worse.



      Looking at IP addresses is often not helpful even if you're looking at the web server logs unless you have a narrow and/or well known band of IP addresses your users connect from. Few attackers do it from their home PC anymore. Bots and proxies are found all over the world plus IPs are easily spoofed. Unless you get your ISP or Telco provider involved, it's unlikely you'll get very far looking at your own logs. One better indicator is your corporate firewall or network logs to find unusual outbound IP targets. An attacker that exfiltrates data has to send it to some real endpoint. That is usually to a place that isn't cooperative and/or moves slowly when foreign companies or law enforcement comes knocking.






      share|improve this answer























        Your Answer








        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "182"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: false,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: null,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f175375%2fis-there-a-way-to-see-if-database-has-been-accessed-through-sql-injection-attack%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        0














        To be pro-active you may have your application to use PDO instead of plain SQL query.



        Measures to detect SQL Injections could be :




        1. Alert if any query running beyond X secs or any breaching value to relevant teams.


        2. The team could see if slow query log / show processlist contains unusual entries, if confirmed as SQL injection kill the query and remove that application user as a preventive measure.







        share|improve this answer




























          0














          To be pro-active you may have your application to use PDO instead of plain SQL query.



          Measures to detect SQL Injections could be :




          1. Alert if any query running beyond X secs or any breaching value to relevant teams.


          2. The team could see if slow query log / show processlist contains unusual entries, if confirmed as SQL injection kill the query and remove that application user as a preventive measure.







          share|improve this answer


























            0












            0








            0







            To be pro-active you may have your application to use PDO instead of plain SQL query.



            Measures to detect SQL Injections could be :




            1. Alert if any query running beyond X secs or any breaching value to relevant teams.


            2. The team could see if slow query log / show processlist contains unusual entries, if confirmed as SQL injection kill the query and remove that application user as a preventive measure.







            share|improve this answer













            To be pro-active you may have your application to use PDO instead of plain SQL query.



            Measures to detect SQL Injections could be :




            1. Alert if any query running beyond X secs or any breaching value to relevant teams.


            2. The team could see if slow query log / show processlist contains unusual entries, if confirmed as SQL injection kill the query and remove that application user as a preventive measure.








            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jun 4 '17 at 17:32









            MannojMannoj

            1,04311128




            1,04311128

























                0














                See Apache's access.log. Interesting things show up there.






                share|improve this answer




























                  0














                  See Apache's access.log. Interesting things show up there.






                  share|improve this answer


























                    0












                    0








                    0







                    See Apache's access.log. Interesting things show up there.






                    share|improve this answer













                    See Apache's access.log. Interesting things show up there.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Jun 4 '17 at 18:25









                    Rick JamesRick James

                    42.9k22259




                    42.9k22259























                        0














                        Since you log all queries against the database, look for queries that don't belong.



                        Start with queries that failed. Assuming your app isn't riddle with bugs, there should be very few queries submitted to the DB that fail. Attackers typically have a set of queries they execute once they find a vulnerable app. If you apply the principle of least privileges on accounts used to access the DB, you should find a bunch of failed queries. There will also be queries that fail because a less sophisticated attacker might have a bunch of queries that are not compatible with your database edition, version or vendor.



                        Next, look for queries/commands that could not have been generated by your application. For instance, if the application should never accesses system tables, system functions, information schema, etc... but you see them in your log, that's a good indicator something might be amiss and warrants deeper investigation. Looking at your OS logs might be helpful here in case they tried or succeeded in planting a backdoor/rootkit.



                        Once you're done with that, look for queries with unusual/unexpected behavior. For instance, queries that return significantly more data than normal. If you see queries that access all tables around the same time or ran show tables then accessed each table in order, there's a good chance you have an attacker that tried (or succeeded) to exfiltrate data. Even something seemingly innocuous like SELECT * without a WHERE clause is suspicious (assuming your app doesn't do this). Note that this applies to any possible query, not just SELECT. The attacker might be some disgruntled employee and decided to randomly DELETE or UPDATE data to get you in trouble with your auditors or worse.



                        Looking at IP addresses is often not helpful even if you're looking at the web server logs unless you have a narrow and/or well known band of IP addresses your users connect from. Few attackers do it from their home PC anymore. Bots and proxies are found all over the world plus IPs are easily spoofed. Unless you get your ISP or Telco provider involved, it's unlikely you'll get very far looking at your own logs. One better indicator is your corporate firewall or network logs to find unusual outbound IP targets. An attacker that exfiltrates data has to send it to some real endpoint. That is usually to a place that isn't cooperative and/or moves slowly when foreign companies or law enforcement comes knocking.






                        share|improve this answer




























                          0














                          Since you log all queries against the database, look for queries that don't belong.



                          Start with queries that failed. Assuming your app isn't riddle with bugs, there should be very few queries submitted to the DB that fail. Attackers typically have a set of queries they execute once they find a vulnerable app. If you apply the principle of least privileges on accounts used to access the DB, you should find a bunch of failed queries. There will also be queries that fail because a less sophisticated attacker might have a bunch of queries that are not compatible with your database edition, version or vendor.



                          Next, look for queries/commands that could not have been generated by your application. For instance, if the application should never accesses system tables, system functions, information schema, etc... but you see them in your log, that's a good indicator something might be amiss and warrants deeper investigation. Looking at your OS logs might be helpful here in case they tried or succeeded in planting a backdoor/rootkit.



                          Once you're done with that, look for queries with unusual/unexpected behavior. For instance, queries that return significantly more data than normal. If you see queries that access all tables around the same time or ran show tables then accessed each table in order, there's a good chance you have an attacker that tried (or succeeded) to exfiltrate data. Even something seemingly innocuous like SELECT * without a WHERE clause is suspicious (assuming your app doesn't do this). Note that this applies to any possible query, not just SELECT. The attacker might be some disgruntled employee and decided to randomly DELETE or UPDATE data to get you in trouble with your auditors or worse.



                          Looking at IP addresses is often not helpful even if you're looking at the web server logs unless you have a narrow and/or well known band of IP addresses your users connect from. Few attackers do it from their home PC anymore. Bots and proxies are found all over the world plus IPs are easily spoofed. Unless you get your ISP or Telco provider involved, it's unlikely you'll get very far looking at your own logs. One better indicator is your corporate firewall or network logs to find unusual outbound IP targets. An attacker that exfiltrates data has to send it to some real endpoint. That is usually to a place that isn't cooperative and/or moves slowly when foreign companies or law enforcement comes knocking.






                          share|improve this answer


























                            0












                            0








                            0







                            Since you log all queries against the database, look for queries that don't belong.



                            Start with queries that failed. Assuming your app isn't riddle with bugs, there should be very few queries submitted to the DB that fail. Attackers typically have a set of queries they execute once they find a vulnerable app. If you apply the principle of least privileges on accounts used to access the DB, you should find a bunch of failed queries. There will also be queries that fail because a less sophisticated attacker might have a bunch of queries that are not compatible with your database edition, version or vendor.



                            Next, look for queries/commands that could not have been generated by your application. For instance, if the application should never accesses system tables, system functions, information schema, etc... but you see them in your log, that's a good indicator something might be amiss and warrants deeper investigation. Looking at your OS logs might be helpful here in case they tried or succeeded in planting a backdoor/rootkit.



                            Once you're done with that, look for queries with unusual/unexpected behavior. For instance, queries that return significantly more data than normal. If you see queries that access all tables around the same time or ran show tables then accessed each table in order, there's a good chance you have an attacker that tried (or succeeded) to exfiltrate data. Even something seemingly innocuous like SELECT * without a WHERE clause is suspicious (assuming your app doesn't do this). Note that this applies to any possible query, not just SELECT. The attacker might be some disgruntled employee and decided to randomly DELETE or UPDATE data to get you in trouble with your auditors or worse.



                            Looking at IP addresses is often not helpful even if you're looking at the web server logs unless you have a narrow and/or well known band of IP addresses your users connect from. Few attackers do it from their home PC anymore. Bots and proxies are found all over the world plus IPs are easily spoofed. Unless you get your ISP or Telco provider involved, it's unlikely you'll get very far looking at your own logs. One better indicator is your corporate firewall or network logs to find unusual outbound IP targets. An attacker that exfiltrates data has to send it to some real endpoint. That is usually to a place that isn't cooperative and/or moves slowly when foreign companies or law enforcement comes knocking.






                            share|improve this answer













                            Since you log all queries against the database, look for queries that don't belong.



                            Start with queries that failed. Assuming your app isn't riddle with bugs, there should be very few queries submitted to the DB that fail. Attackers typically have a set of queries they execute once they find a vulnerable app. If you apply the principle of least privileges on accounts used to access the DB, you should find a bunch of failed queries. There will also be queries that fail because a less sophisticated attacker might have a bunch of queries that are not compatible with your database edition, version or vendor.



                            Next, look for queries/commands that could not have been generated by your application. For instance, if the application should never accesses system tables, system functions, information schema, etc... but you see them in your log, that's a good indicator something might be amiss and warrants deeper investigation. Looking at your OS logs might be helpful here in case they tried or succeeded in planting a backdoor/rootkit.



                            Once you're done with that, look for queries with unusual/unexpected behavior. For instance, queries that return significantly more data than normal. If you see queries that access all tables around the same time or ran show tables then accessed each table in order, there's a good chance you have an attacker that tried (or succeeded) to exfiltrate data. Even something seemingly innocuous like SELECT * without a WHERE clause is suspicious (assuming your app doesn't do this). Note that this applies to any possible query, not just SELECT. The attacker might be some disgruntled employee and decided to randomly DELETE or UPDATE data to get you in trouble with your auditors or worse.



                            Looking at IP addresses is often not helpful even if you're looking at the web server logs unless you have a narrow and/or well known band of IP addresses your users connect from. Few attackers do it from their home PC anymore. Bots and proxies are found all over the world plus IPs are easily spoofed. Unless you get your ISP or Telco provider involved, it's unlikely you'll get very far looking at your own logs. One better indicator is your corporate firewall or network logs to find unusual outbound IP targets. An attacker that exfiltrates data has to send it to some real endpoint. That is usually to a place that isn't cooperative and/or moves slowly when foreign companies or law enforcement comes knocking.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Jun 22 '17 at 1:38









                            SQLmojoeSQLmojoe

                            1,32037




                            1,32037






























                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to Database Administrators Stack Exchange!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f175375%2fis-there-a-way-to-see-if-database-has-been-accessed-through-sql-injection-attack%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Armoriale delle famiglie italiane (Car) Indice Armi | Bibliografia | Menu di navigazioneBlasone...

                                Why does this relation fail symmetry and transitivity properties?Properties of Relations. Reflexive,...

                                why typing a variable (or expression) prints the value to stdout?Calling a function of a module by using its...