-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
487de21
commit b20cf8e
Showing
31 changed files
with
272 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# CheckPoint | ||
|
||
CheckPoint封禁模块 | ||
|
||
## 下载模块 | ||
|
||
``` | ||
wget https://raw.githubusercontent.com/sec-report/SecAutoBan/main/device/block/check_point/check_point.py | ||
``` | ||
|
||
## 配置CheckPoint | ||
|
||
### 开启Management API | ||
|
||
![](./img/1.jpg) | ||
|
||
### 新建网络分组 | ||
|
||
`新建-网络分组`弹出框新建分组`sec_auto_ban`并保存: | ||
|
||
![](./img/2.jpg) | ||
|
||
### 为网络分组创建封禁规则 | ||
|
||
在`安全策略-访问控制-策略`页面新建两条规则,分别为阻止源为`sec_auto_ban`及目的为`sec_auto_ban`,图例: | ||
|
||
![](./img/3.jpg) | ||
|
||
## 配置模块 | ||
|
||
### 安装依赖 | ||
|
||
``` | ||
pip3 install SecAutoBan requests | ||
``` | ||
|
||
### 修改配置 | ||
|
||
#### 修改回连核心模块配置 | ||
|
||
更改脚本第`159`-`161`行 | ||
|
||
``` | ||
server_ip = "127.0.0.1", | ||
server_port = 80, | ||
sk = "sk-xxx", | ||
``` | ||
|
||
#### 修改与CheckPoint连接的地址 | ||
|
||
更改脚本第`153`行 | ||
|
||
``` | ||
"url": "http://xxx.xxx.xxx.xxx", | ||
``` | ||
|
||
#### 填写CheckPoint用户名密码 | ||
|
||
更改脚本第`154`-`155`行 | ||
|
||
``` | ||
"username": "admin", | ||
"password": "", | ||
``` | ||
|
||
## 运行 | ||
|
||
```shell | ||
python3 check_point.py | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
import time | ||
import signal | ||
import requests | ||
from SecAutoBan import SecAutoBan | ||
from multiprocessing.pool import ThreadPool | ||
requests.packages.urllib3.disable_warnings() | ||
|
||
|
||
def signal_handler(signal, frame): | ||
sec_auto_ban.print("[+] 注销Session") | ||
publish() | ||
logout() | ||
exit() | ||
|
||
|
||
def login(): | ||
post_json = { | ||
"user": check_point_conf["username"], | ||
"password": check_point_conf["password"], | ||
} | ||
r = requests.post(check_point_conf["url"] + "/web_api/login", json=post_json, verify=False) | ||
if r.status_code == 200 and "sid" in r.json(): | ||
sec_auto_ban.print("[+] 防火墙登录成功") | ||
else: | ||
sec_auto_ban.print("[-] 防火墙登录失败") | ||
exit() | ||
global check_point_session_id | ||
check_point_session_id = r.json()["sid"] | ||
|
||
|
||
def discard(): | ||
header = { | ||
"X-chkp-sid": check_point_session_id | ||
} | ||
requests.post(check_point_conf["url"] + "/web_api/discard", json={}, headers=header, verify=False) | ||
|
||
|
||
def publish(): | ||
header = { | ||
"X-chkp-sid": check_point_session_id | ||
} | ||
r = requests.post(check_point_conf["url"] + "/web_api/publish", json={}, headers=header, verify=False) | ||
if "task-id" not in r.json(): | ||
sec_auto_ban.print("[-] 推送失败,回退session") | ||
discard() | ||
|
||
|
||
def logout(): | ||
header = { | ||
"X-chkp-sid": check_point_session_id | ||
} | ||
requests.post(check_point_conf["url"] + "/web_api/logout", json={}, headers=header, verify=False) | ||
|
||
|
||
def keepalive(): | ||
time.sleep(60) | ||
header = { | ||
"X-chkp-sid": check_point_session_id | ||
} | ||
r = requests.post(check_point_conf["url"] + "/web_api/keepalive", json={}, headers=header, verify=False) | ||
if r.status_code != 200: | ||
login() | ||
keepalive() | ||
|
||
|
||
def check_host(ip: str) -> str: | ||
post_json = { | ||
"filter": ip | ||
} | ||
header = { | ||
"X-chkp-sid": check_point_session_id | ||
} | ||
r = requests.post(check_point_conf["url"] + "/web_api/show-hosts", json=post_json, headers=header, verify=False) | ||
if "total" in r.json(): | ||
if r.json()["total"] == 0: | ||
return "" | ||
return r.json()["objects"][0]["uid"] | ||
return "" | ||
|
||
|
||
def get_host_uid(ip: str) -> str: | ||
uid = check_host(ip) | ||
if len(uid) != 0: | ||
return uid | ||
post_json = { | ||
"name": "block_" + ip, | ||
"ip-address": ip | ||
} | ||
header = { | ||
"X-chkp-sid": check_point_session_id | ||
} | ||
r = requests.post(check_point_conf["url"] + "/web_api/add-host", json=post_json, headers=header, verify=False) | ||
return r.json()["uid"] | ||
|
||
|
||
def block_ip(ip): | ||
if check_exist_ip(ip): | ||
return | ||
host_uid = get_host_uid(ip) | ||
if len(host_uid) == 0: | ||
sec_auto_ban.print("[-] IP: " + ip + " 添加失败") | ||
post_json = { | ||
"name": check_point_conf["group_name"], | ||
"members": { | ||
"add": host_uid | ||
}, | ||
"details-level": "uid" | ||
} | ||
header = { | ||
"X-chkp-sid": check_point_session_id | ||
} | ||
requests.post(check_point_conf["url"] + "/web_api/set-group", json=post_json, headers=header, verify=False) | ||
publish() | ||
|
||
|
||
def unblock_ip(ip): | ||
if not check_exist_ip(ip): | ||
return | ||
host_uid = get_host_uid(ip) | ||
if len(host_uid) == 0: | ||
sec_auto_ban.print("[-] IP: " + ip + " 删除失败") | ||
post_json = { | ||
"name": check_point_conf["group_name"], | ||
"members": { | ||
"remove": host_uid | ||
}, | ||
} | ||
header = { | ||
"X-chkp-sid": check_point_session_id | ||
} | ||
requests.post(check_point_conf["url"] + "/web_api/set-group", json=post_json, headers=header, verify=False) | ||
publish() | ||
|
||
|
||
def get_all_block_ip() -> list: | ||
post_json = { | ||
"name": check_point_conf["group_name"] | ||
} | ||
header = { | ||
"X-chkp-sid": check_point_session_id | ||
} | ||
r = requests.post(check_point_conf["url"] + "/web_api/show-group", json=post_json, headers=header, verify=False) | ||
return [i["ipv4-address"]for i in r.json()["members"]] | ||
|
||
|
||
def check_exist_ip(ip) -> bool: | ||
return ip in get_all_block_ip() | ||
|
||
|
||
if __name__ == "__main__": | ||
check_point_session_id = "" | ||
check_point_conf = { | ||
"url": "https://xxx.xxx.xxx.xxx", | ||
"username": "admin", | ||
"password": "", | ||
"group_name": "sec_auto_ban" | ||
} | ||
sec_auto_ban = SecAutoBan( | ||
server_ip="127.0.0.1", | ||
server_port=80, | ||
sk="sk-*****", | ||
client_type="block", | ||
block_ip = block_ip, | ||
unblock_ip = unblock_ip, | ||
get_all_block_ip= get_all_block_ip | ||
) | ||
pool = ThreadPool(processes=1) | ||
login() | ||
pool.apply_async(keepalive) | ||
signal.signal(signal.SIGINT, signal_handler) | ||
sec_auto_ban.run() |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.