10 Commits

Author SHA1 Message Date
风起 6ca5f302df Update RedGuard Version 22.7.14 2022-07-14 10:45:56 +08:00
风起 6c4b78b692 Update README.md 2022-07-12 12:19:52 +08:00
风起 54240373ea Update CHANGELOG 2022-07-12 12:17:02 +08:00
风起 e41fdb7bd2 Update ProxyFilter.go 2022-07-12 12:08:33 +08:00
风起 c7a4657a2b Delete RedGuard 2022-07-12 12:07:12 +08:00
风起 f51f9ae381 Update RedGuard Version 22.7.12 2022-07-12 12:06:07 +08:00
风起 7ff6cc59e1 Update RedGuard Version 22.7.4.11.30 2022-07-04 13:41:04 +08:00
风起 26719ed09e Update ProxyHandler.go 2022-07-04 11:24:00 +08:00
风起 0281902237 Update ProxyHandler.go 2022-07-04 11:20:23 +08:00
风起 79d6718f8d Update README.md 2022-07-01 10:37:30 +08:00
16 changed files with 155 additions and 1666 deletions
+12 -3
View File
@@ -1,6 +1,15 @@
## [22.6.30.1107] - 2022-6-30
## [22.7.14.1043] - 2022-7-14
### Added
- Domain fronting Obtain the actual requested IP address
- Resolve the problem that the custom certificate is overwritten
## [22.7.12.1111] - 2022-7-12
### Added
- Profile Header authentication ignores case
- Disable the default JARM fingerprint randomization parameter
- Change the long version name!!
- Forward the packet XFF header so that C2 gets the real IP address
- Custom configuration file path
- Added validity verification for parameter IP input
## [22.6.28.1712] - 2022-6-28
### Added
@@ -15,4 +24,4 @@ due to the incompatibility of TLS jarm fingerprint randomize with custom certifi
## [22.5.20.1220] - 2022-5-20
### Added
- Initialize project
- Initialize project
+12 -1
View File
@@ -152,7 +152,7 @@ As shown in the figure above, in the case of unauthorized access, the response i
In the above basic interception case, the default interception method is used, that is, the illegal traffic is intercepted by redirection. By modifying the configuration file, we can change the interception method and the redirected site URL. In fact, this The other way is a redirect, which might be more aptly described as hijacking, cloning, since the response status code returned is 200, and the response is taken from another website to mimic the cloned/hijacked website as closely as possible.
Invalid packets can be misrouted according to two strategies:
Invalid packets can be misrouted according to three strategies:
- **reset**: Terminate the TCP connection immediately.
- **proxy**: Get a response from another website to mimic the cloned/hijacked website as closely as possible.
@@ -196,6 +196,17 @@ The blue team tracing behavior is analyzed through the interception log of the t
![image.png](https://github.com/wikiZ/RedGuardImage/raw/main/1656310909975.jpg)
## RedGuard Obtain the real IP address
This section describes how to configure RG to obtain the real IP address of a request. You only need to add the following configuration to the profile of the C2 device, that is, to obtain the real IP address of the target through the request header X-Forwarded-For.
```bash
http-config {
set trust_x_forwarded_for "true";
}
```
## Request geographic restrictions
The configuration method takes AllowLocation = Jinan, Beijing as an example. It is worth noting here that RedGuard provides two APIs for IP attribution anti-check, one for domestic users and the other for overseas users. Dynamically assign which API to use. If the target is in China, enter Chinese for the set region. Otherwise, enter English place names. It is recommended that domestic users use Chinese names. In this way, the accuracy of the attribution found and the response speed of the API are both is the best choice.
+5 -1
View File
@@ -84,12 +84,16 @@ func main() {
)
core.CmdParse(&parse, &cert, &_proxy)
// Check whether RedGuard has been initialized
if num, isExits := lib.CreateConfig(parse.C2Type /* C2 Facility Type */); isExits {
if num, isExits := lib.CreateConfig(parse.C2Type /* C2 Facility Type */, parse.ConfigPath); isExits {
switch {
case parse.Update:
lib.UpdateConfig(&cert, &_proxy) // Update RedGuard Config
logger.Notice("RedGuard Configuration file updated successfully!")
case parse.IP != "":
if lib.CheckIP(parse.IP) == false {
logger.Warning("Please enter a valid IP address")
os.Exit(0)
}
logger.Noticef("Search ipLookUpHelper: %s", parse.IP)
core.IPLookUp(parse.Location /* owning place to be verified */, parse.IP) // Query the location of an IP address
case num == 0:
+21 -1598
View File
File diff suppressed because it is too large Load Diff
+18 -18
View File
@@ -1,24 +1,24 @@
-----BEGIN CERTIFICATE-----
MIIEFTCCAv2gAwIBAgIIFv1FwrYv9MwwDQYJKoZIhvcNAQELBQAwZjELMAkGA1UE
MIIEFDCCAvygAwIBAgIIFwGR46UNXCwwDQYJKoZIhvcNAQELBQAwZjELMAkGA1UE
BhMCQ04xETAPBgNVBAcTCEhhbmdaaG91MS0wKwYDVQQKEyRBbG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/O4NqfS4OQPC+1xNFrN
P2kxHaMRO6FX0GqzSt6rH1y1ngEpDxKZ9Sdw04anaGm3j+iGU2O0woTZqOSVZKYb
TQI8sGaEmzFwkZTArPm8zNWDiqnJUIOfmcBSYSDt1XktpgcSBqK6GpXbplUt4N3u
gNJRAoGBAIo2SQXHObtfphpMVoDZm3A2DubekPuY5aHx0x5U24IDcF/19AJ3SvOh
U7NHpHgGDal5WhLN9dIRBxujP/BL1TAKPpf6P5x4o1Jva0tUWcLvTzAM6NgFMY+0
p4z+rF2IIkG383nWDpSL3r+0mpUEaPY5iCO8fyUQQtIr6gt+o8PW
-----END RSA PRIVATE KEY-----
+1 -1
View File
@@ -12,7 +12,7 @@ Organization = Alibaba (China) Technology Co., Ltd.
# Cert User Country
Country = CN
# Whether to use the certificate you have applied for true/false
HasCert = false
HasCert = true
[proxy]
# key : Header Host value of the reverse proxy
+1 -1
View File
@@ -21,7 +21,7 @@ Github:%s
RedGuard is a C2 front flow control tool,Can avoid Blue Teams,AVs,EDRs check.
`
VERSION = "22.6.30.1107 Alpha"
VERSION = "22.7.14 Alpha"
TITLE = "RedGuard"
LICENSE = "GPL-2.0"
URL = "https://github.com/wikiZ/RedGuard"
+1 -1
View File
@@ -94,7 +94,7 @@ func MalleableFilter(file string, req *http.Request) (isFilter bool) {
var num int // Exception counter
// Traverse the target profile requirements header slice
for _, profileHeader := range malleable.headerParam {
if reqHeader != profileHeader {
if strings.ToLower(reqHeader) != strings.ToLower(profileHeader) {
continue
}
num += 1 // The same header exists
+7 -5
View File
@@ -51,7 +51,7 @@ func modifyResponse(drop bool) func(*http.Response) error {
logger.Warningf("[RESPONSE] HTTP %s, length: %d", resp.Status, resp.ContentLength)
if drop {
// DROP Request
logger.Alertf("[DROP] Source IP: %s", ip)
logger.Alertf("[DROP] Source IP: %s", resp.Request.RemoteAddr)
_ = Body.Close() // Direct shutdown response
return
}
@@ -79,11 +79,13 @@ func (h *baseHandle) ServeHTTP(write http.ResponseWriter, req *http.Request) {
var proxy *httputil.ReverseProxy
// Determine the URL to be redirected to
redirectURL = lib.ReadConfig("proxy", "Redirect", cfg)
ip = lib.ConvertIP(req.RemoteAddr)
req.RemoteAddr = lib.ConvertIP(req.RemoteAddr)
// Obtaining the real IP address
if req.Header.Get("X-Forwarded-For") != "" {
ip = req.Header.Get("X-Forwarded-For")
req.RemoteAddr = req.Header.Get("X-Forwarded-For")
}
// Set the forwarding header XFF so that C2 obtains the online real IP address
req.Header.Set("X-Forwarded-For", req.RemoteAddr)
// Check whether the host is verified
if IPHash := lib.EncodeMD5(req.JA3); arrays.ContainsString(_addressArray, req.JA3) == -1 {
logger.Noticef("JA3 FingerPrint: %s", IPHash)
@@ -92,7 +94,7 @@ func (h *baseHandle) ServeHTTP(write http.ResponseWriter, req *http.Request) {
if !ProxyFilterManger(req) {
goto LOOK // Redirect to the specified site
}
logger.Noticef("[REQUEST] %s - %s", ip, req.UserAgent())
logger.Noticef("[REQUEST] %s - %s", req.RemoteAddr, req.UserAgent())
_addressArray = append(_addressArray, IPHash) // Add to the list after verification for the first time
}
// Fetch directly from cache
@@ -137,7 +139,7 @@ LOOK:
proxy.ServeHTTP(write, req)
REDIRECT:
// REDIRECT Request
logger.Alertf("[%s] Source IP: %s -> Destination Site: %s", strings.ToUpper(dropAction), ip, redirectURL)
logger.Alertf("[%s] Source IP: %s -> Destination Site: %s", strings.ToUpper(dropAction), req.RemoteAddr, redirectURL)
}
// ProxyManger Initialize the reverse proxy and pass in the address of the real back-end service
+2 -1
View File
@@ -17,11 +17,12 @@ func CmdParse(parse *parameter.Parses, cert *parameter.Cert, proxy *parameter.Pr
flag.BoolVar(&parse.Update, "u", false, `Enable configuration file modification`)
flag.StringVar(&parse.C2Type, "type", `CobaltStrike`, `C2 Server Type`)
flag.StringVar(&parse.IP, "ip", ``, `IPLookUP IP`)
flag.StringVar(&parse.ConfigPath, "config", ``, `Set Config Path`)
flag.StringVar(&parse.Location, "location", `风起`, `IPLookUP Location`)
flag.StringVar(&cert.Country, "country", `CN`, `Cert Country`)
flag.StringVar(&cert.CommonName, "common", `*.aliyun.com`, `Cert CommonName`)
flag.StringVar(&cert.Organization, "organization", `Alibaba (China) Technology Co., Ltd.`, `Cert Organization`)
flag.StringVar(&cert.HasCert, "HasCert", `false`, `Whether to use the certificate you have applied for`)
flag.StringVar(&cert.HasCert, "HasCert", `true`, `Whether to use the certificate you have applied for`)
flag.StringVar(&cert.DNSNameTo, "dns", `*.aliyun.com,manager.channel.aliyun.com,*.acs-internal.aliyuncs.com",*.connect.aliyun.com,aliyun.com,whois.www.net.cn,tianchi-global.com`, `Cert DNSName`)
flag.StringVar(&cert.Locality, "locality", `HangZhou`, `Cert Locality`)
flag.StringVar(&proxy.HostTarget, "host", `{"360.net":"http://127.0.0.1:8080","360.com":"https://127.0.0.1:4433"}`, `Set Proxy HostTarget`)
+5 -4
View File
@@ -8,10 +8,11 @@
package parameter
type Parses struct {
Update bool
C2Type string
IP string
Location string
Update bool
IP string
C2Type string
Location string
ConfigPath string
}
type Cert struct {
+11 -1
View File
@@ -150,7 +150,7 @@ Usage of ./RedGuard:
上述的基础拦截案例中,使用的是默认的拦截方式,也就是将非法流量以重定向的方式拦截,而通过配置文件的修改,我们可以更改拦截的方式,以及重定向的站点URL,其实这种方式与之说是重定向,描述为劫持、克隆或许更贴切,因为返回的响应状态码为200,是从另一个网站获取响应,以尽可能接近地模仿克隆/劫持的网站。
无效数据包可能会根据种策略被错误路由:
无效数据包可能会根据种策略被错误路由:
- **reset**:立即终止 TCP 连接。
- **proxy**:从另一个网站获取响应,以尽可能接近地模仿克隆/劫持的网站。
@@ -194,6 +194,16 @@ Port_HTTP = :80
![image.png](https://github.com/wikiZ/RedGuardImage/raw/main/1656310909975.jpg)
## RedGuard获取真实IP地址
针对于日常、域前置场景下获取真实请求IP,RG无需进行任何配置,仅需对启动C2设施的profile文件增加以下配置,即通过请求头X-Forwarded-For获取目标真实IP。
```bash
http-config {
set trust_x_forwarded_for "true";
}
```
## 请求地域限制
配置方式以AllowLocation = 济南,北京 为例,这里值得注意的是,RedGuard提供了两个IP归属地反查的API,一个适用于国内用户,另一个适用于海外用户,并且可以根据输入的地域名动态的分配使用哪个API,如果目标是中国的那么设置的地域就输入中文,反之输入英文地名,建议国内的用户使用中文名即可,这样反查到的归属地准确度以及API的响应速度都是最好的选择。
+6
View File
@@ -89,6 +89,12 @@ func GenerateSelfSignedCert(cert *parameter.Cert) {
}
func InitGenerateSelfSignedCert() {
// Check whether an SSL certificate is generated
if _existsCrt, _ := FileExists("cert-rsa/ca.crt"); _existsCrt {
if _existsKey, _ := FileExists("cert-rsa/ca.key"); _existsKey {
return
}
}
// Example Create a CA certificate storage directory
if _, err := os.Stat("cert-rsa"); err != nil {
_ = os.Mkdir("cert-rsa", 0766) // Directory permissions
+20
View File
@@ -11,6 +11,7 @@ import (
"crypto/md5"
"encoding/hex"
"encoding/json"
"os"
"regexp"
)
@@ -37,3 +38,22 @@ func EncodeMD5(s string) string {
md5Str := hex.EncodeToString(hash.Sum(nil))
return md5Str
}
// CheckIP Check whether the entered IP address is valid
func CheckIP(ip string) bool {
if m, _ := regexp.MatchString("^(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)\\.(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)\\.(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)\\.(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)$", ip); !m {
return false
}
return true
}
func FileExists(path string) (bool, error) {
_, err := os.Stat(path)
if err == nil {
return true, nil
}
if os.IsNotExist(err) {
return false, nil
}
return false, err
}
+8 -6
View File
@@ -8,13 +8,13 @@
package lib
import (
"RedGuard/config"
"RedGuard/core/parameter"
"fmt"
"io/ioutil"
"os"
"os/user"
"RedGuard/config"
"github.com/go-ini/ini"
)
@@ -30,17 +30,19 @@ func InitConfig() *ini.File {
// Check whether loading failed
if err != nil {
logger.Errorf("Fail to read file: %v", err)
goto LOOK
os.Exit(0)
}
// return *ini.File object
return cfg
LOOK:
return nil
}
func CreateConfig(C2Server string) (int, bool) {
func CreateConfig(C2Server string, ConfigPath string) (int, bool) {
currentUser, _ := user.Current() // Current operating system user directory
_ConfigFilename = fmt.Sprintf("%s/.RedGuard_%s.ini", currentUser.HomeDir, C2Server)
// Verify that the configuration file is customized
if file, _ := ioutil.ReadFile(ConfigPath); len(file) != 0 {
_ConfigFilename = ConfigPath // Configuration file using a custom path
}
// Check whether the current operating system user directory configuration file exists
if _, err := os.Stat(_ConfigFilename); err == nil || os.IsExist(err) {
return 0, true