6 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
16 changed files with 148 additions and 1825 deletions
+10 -5
View File
@@ -1,10 +1,15 @@
## [22.7.4.11.30] - 2022-7-4
## [22.7.14.1043] - 2022-7-14
### Added
- Fix inconsistent request IP address and interception IP address Domain fronting
- Resolve the problem that the custom certificate is overwritten
## [22.6.30.1107] - 2022-6-30
## [22.7.12.1111] - 2022-7-12
### Added
- Domain fronting Obtain the actual requested IP address
- 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
@@ -19,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 -1759
View File
File diff suppressed because it is too large Load Diff
+18 -18
View File
@@ -1,24 +1,24 @@
-----BEGIN CERTIFICATE-----
MIIEFTCCAv2gAwIBAgIIFv6CRztNa1AwDQYJKoZIhvcNAQELBQAwZjELMAkGA1UE
MIIEFDCCAvygAwIBAgIIFwGR46UNXCwwDQYJKoZIhvcNAQELBQAwZjELMAkGA1UE
BhMCQ04xETAPBgNVBAcTCEhhbmdaaG91MS0wKwYDVQQKEyRBbGliYWJhIChDaGlu
YSkgVGVjaG5vbG9neSBDby4sIEx0ZC4xFTATBgNVBAMMDCouYWxpeXVuLmNvbTAe
Fw0yMjA3MDQwMzIyMzVaFw0yMzA3MDQwMzIyMzVa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SYSDt1XktpgcSBqK6GpXbplUt4N3u
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.7.4.11.30 Alpha"
VERSION = "22.7.14 Alpha"
TITLE = "RedGuard"
LICENSE = "GPL-2.0"
URL = "https://github.com/wikiZ/RedGuard"
+1 -2
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
@@ -132,7 +132,6 @@ func ProxyFilterManger(req *http.Request) (status bool) {
}
}
}
// Check the location of the requested IP address
if allowLocation != "" && allowLocation != "*" {
// @param allowLocation string The territory that is allowed to go online
+2
View File
@@ -84,6 +84,8 @@ func (h *baseHandle) ServeHTTP(write http.ResponseWriter, req *http.Request) {
if 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)
+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