SQL×¢Èë·¨¹¥»÷ Ïê½â
Ëæ×ÅB/SģʽӦÓÿª·¢µÄ·¢Õ¹£¬Ê¹ÓÃÕâÖÖģʽ±àдӦÓóÌÐòµÄ³ÌÐòÔ±Ò²Ô½À´Ô½¶à¡£µ«ÊÇÓÉÓÚ³ÌÐòÔ±µÄˮƽ¼°¾ÑéÒ²²Î²î²»Æ룬Ï൱´óÒ»²¿·Ö³ÌÐòÔ±ÔÚ±àд´úÂëµÄʱºò£¬Ã»ÓжÔÓû§ÊäÈëÊý¾ÝµÄºÏ·¨ÐÔ½øÐÐÅжϣ¬Ê¹Ó¦ÓóÌÐò´æÔÚ°²È«Òþ»¼¡£Óû§¿ÉÒÔÌá½»Ò»¶ÎÊý¾Ý¿â²éѯ´úÂ룬¸ù
¾Ý³ÌÐò·µ»ØµÄ½á¹û£¬»ñµÃijЩËûÏëµÃÖªµÄÊý¾Ý£¬Õâ¾ÍÊÇËùνµÄSQL Injection£¬¼´SQL×¢Èë¡£
SQL×¢ÈëÊÇ´ÓÕý³£µÄWWW¶Ë¿Ú·ÃÎÊ£¬¶øÇÒ±íÃæ¿´ÆðÀ´¸úÒ»°ãµÄWebÒ³Ãæ·ÃÎÊûʲôÇø±ð£¬ËùÒÔÄ¿Ç°ÊÐÃæµÄ·À»ðǽ¶¼²»»á¶ÔSQL×¢Èë·¢³ö¾¯±¨£¬Èç¹û¹ÜÀíԱû²é¿´IISÈÕÖ¾µÄÏ°¹ß£¬¿ÉÄܱ»ÈëÇֺܳ¤Ê±¼ä¶¼²»»á·¢¾õ¡£µ«ÊÇ£¬SQL×¢ÈëµÄÊÖ·¨Ï൱Áé»î£¬ÔÚ×¢ÈëµÄʱºò»áÅöµ½ºÜ¶àÒâÍâµÄÇé¿ö¡£Äܲ»Äܸù¾Ý¾ßÌåÇé¿ö½øÐзÖÎö£¬¹¹ÔìÇÉÃîµÄSQLÓï¾ä£¬´Ó¶ø³É¹¦»ñÈ¡ÏëÒªµÄÊý¾Ý¡£
¾Ýͳ¼Æ£¬ÍøÕ¾ÓÃASP+Access»òSQLServerµÄÕ¼70%ÒÔÉÏ£¬PHP+MySQÕ¼L20%£¬ÆäËûµÄ²»×ã10%¡£ÔÚ±¾ÎÄ£¬ÒÔSQL-SERVER£«ASPÀý˵Ã÷SQL×¢ÈëµÄÔÀí¡¢·½·¨Óë¹ý³Ì¡££¨PHP×¢ÈëµÄÎÄÕÂÓÉNBÁªÃ˵ÄÁíһλÅóÓÑzwell׫дµÄÓйØÎÄÕ£©
SQL×¢Èë¹¥»÷µÄ×ÜÌå˼·ÊÇ£º
l ·¢ÏÖSQL×¢ÈëλÖã»
l ÅжϺǫ́Êý¾Ý¿âÀàÐÍ£»
l È·¶¨XP_CMDSHELL¿ÉÖ´ÐÐÇé¿ö
l ·¢ÏÖWEBÐéÄâĿ¼
l ÉÏ´«ASPľÂí£»
l µÃµ½¹ÜÀíԱȨÏÞ£»
Ò»¡¢SQL×¢È멶´µÄÅжÏ
Ò»°ãÀ´Ëµ£¬SQL×¢ÈëÒ»°ã´æÔÚÓÚÐÎÈ磺HTTP://xxx.xxx.xxx/abc.asp?id=XXµÈ´øÓвÎÊýµÄASP¶¯Ì¬ÍøÒ³ÖУ¬ÓÐʱһ¸ö¶¯Ì¬ÍøÒ³ÖпÉÄÜÖ»ÓÐÒ»¸ö²ÎÊý£¬ÓÐʱ¿ÉÄÜÓÐN¸ö²ÎÊý£¬ÓÐʱÊÇÕûÐͲÎÊý£¬ÓÐʱÊÇ×Ö·û´®ÐͲÎÊý£¬²»ÄÜÒ»¸Å¶øÂÛ¡£×ÜÖ®Ö»ÒªÊÇ´øÓвÎÊýµÄ¶¯Ì¬ÍøÒ³ÇÒ´ËÍøÒ³·ÃÎÊÁËÊý¾Ý¿â£¬ÄÇô¾ÍÓпÉÄÜ´æÔÚSQL×¢Èë¡£Èç¹ûASP³ÌÐòԱûÓа²È«Òâʶ£¬²»½øÐбØÒªµÄ×Ö·û¹ýÂË£¬´æÔÚSQL×¢ÈëµÄ¿ÉÄÜÐԾͷdz£´ó¡£
ΪÁËÈ«ÃæÁ˽⶯̬ÍøÒ³»Ø´ðµÄÐÅÏ¢£¬Ê×Ñ¡Çëµ÷ÕûIEµÄÅäÖᣰÑIE²Ëµ¥-¹¤¾ß-InternetÑ¡Ï߼¶£ÏÔʾÓѺÃHTTP´íÎóÐÅϢǰÃæµÄ¹´È¥µô¡£
ΪÁË°ÑÎÊÌâ˵Ã÷Çå³þ£¬ÒÔÏÂÒÔHTTP://xxx.xxx.xxx/abc.asp?p=YYΪÀý½øÐзÖÎö£¬YY¿ÉÄÜÊÇÕûÐÍ£¬Ò²ÓпÉÄÜÊÇ×Ö·û´®¡£
1¡¢ÕûÐͲÎÊýµÄÅжÏ
µ±ÊäÈëµÄ²ÎÊýYYΪÕûÐÍʱ£¬Í¨³£abc.aspÖÐSQLÓï¾äÔò´óÖÂÈçÏ£º
select * from ±íÃû where ×Ö¶Î=YY£¬ËùÒÔ¿ÉÒÔÓÃÒÔϲ½Öè²âÊÔSQL×¢ÈëÊÇ·ñ´æÔÚ¡£
¢ÙHTTP://xxx.xxx.xxx/abc.asp?p=YY’(¸½¼ÓÒ»¸öµ¥ÒýºÅ)£¬´Ëʱabc.ASPÖеÄSQLÓï¾ä±ä³ÉÁË
select * from ±íÃû where ×Ö¶Î=YY’£¬abc.aspÔËÐÐÒì³££»
¢ÚHTTP://xxx.xxx.xxx/abc.asp?p=YY and 1=1, abc.aspÔËÐÐÕý³££¬¶øÇÒÓëHTTP://xxx.xxx.xxx/abc.asp?p=YYÔËÐнá
Ïà¹ØÎĵµ£º
ͨ¹ýSqlÓï¾ä»ñµÃ ÁеÄÀàÐͺÍ˵Ã÷:
µÃµ½µÄ±íÍ·£º±íÃû|ÁÐÃû|ÀàÐÍ|˵Ã÷
1£ºÕë¶Ôsql server 2000£¬ÔÚsql2000ÖУ¬Ê¹Óãºsysobjects,syscolumnsºÍsysproperties±í
SELECT o.name as table_name,c.name AS col_name,type_name(c.xtype) AS type_name,isnull(p.value,'') AS col_Pro ......
SQL ×¢Èë¹¥»÷ÔÀí¼°·À»¤
ÔÚÈ·ÈÏ¿ÉÒÔ×¢ÈëµÄÇé¿öÏ£¬Ê¹ÓÃÏÂÃæµÄÓï¾ä£º
HTTP://www.163.com/news.asp?id=xx ;and (select count(*) from sysobjects)£¾0
HTTP://www.163.com/news.asp?id=xx ;and (select count(*) from msysobjects)£¾0
Èç¹ûÊý¾Ý¿âÊÇSQLServer£¬ÄÇôµÚÒ»¸öÍøÖ·µÄÒ³ÃæÓëÔÒ³ÃæHTTP://www.163.com/news.asp? ......
--ÈÕÆÚת»»²ÎÊý,ÖµµÃÊÕ²Ø
select CONVERT(varchar, getdate(), 120 )2004-09-12 11:06:08
select replace(replace(replace(CONVERT(varchar, getdate(), 120 ),'-',''),' ',''),':','')20040912110608
select CONVERT(varchar(12) , getdate(), 111 )2004/09/12
select CONVERT(varchar(12) , getdate(), 112 )20040912 ......
PowerBuilderÊÇÄ¿Ç°×îÁ÷ÐеÄÊý¾Ý¿â¿ª·¢¹¤¾ßÖ®Ò»¡£PowerBuilderÌṩÁËÔÚ³ÌÐò´úÂëÖмÓÈëǶÈëʽSQLÓï¾äµÄ¹¦ÄÜÀ´Ö§³Ö¶ÔÊý¾Ý¿âµÄ·ÃÎÊ¡£µ«ÕâÖÖǶÈëʽSQLÓï¾äÖ»ÄÜÖ§³ÖһЩ¹Ì¶¨µÄ±ê×¼µÄSQLÓï¾ä£¬¼´ÔÚ½øÐгÌÐò´úÂë±àÒë´¦ÀíʱÕâЩSQLÓï¾ä±ØÐëÊÇÈ·¶¨µÄ£¬ÀýÈ磺¶ÔÄÄÕűíÄļ¸¸ö×ֶνøÐвÙ×÷ÔÚ³ÌÐò´úÂëÖÐÊǹ̶¨Ð´Ã÷µÄ£¬ÁíÍâÕâÖÖ·½Ê½Ò²²»ÄÜ ......
1. GROUP BY ÊÇ·Ö×é²éѯ, Ò»°ã GROUP BY ÊǺ;ۺϺ¯ÊýÅäºÏʹÓÃ
group by ÓÐÒ»¸öÔÔò,¾ÍÊÇ select ºóÃæµÄËùÓÐÁÐÖÐ,ûÓÐʹÓþۺϺ¯ÊýµÄÁÐ,±ØÐë³öÏÖÔÚ group by ºóÃ棨ÖØÒª£©
ÀýÈç,ÓÐÈçÏÂÊý¾Ý¿â±í£º
A B
1 abc
1 bcd
1 asdfg
Èç¹ûÓÐÈ ......