Azoko antoka fa izay rehetra niara-niasa taminy
Nisy “fahagagana” nitranga vao haingana. Miaraka amin'ny famoahana ny dikan-teny vaovao Gaia R80 nambara ny fahafahana Fampiasana API, izay manokatra fahafahana midadasika ho an'ny fampandehanana automatique, fitantanana, fanaraha-maso, sns. Afaka izao ianao:
- mamorona zavatra;
- manampy na manova ny lisitry ny fidirana;
- avelao / esory ny lelany;
- amboary ny fifandraisana amin'ny tambajotra;
- mametraka politika;
- ary mihoatra noho izany aza.
Raha ny marina, tsy azoko ny fomba nandalovan'i Habr ity vaovao ity. Amin'ity lahatsoratra ity dia hamariparitra fohifohy ny fomba fampiasana ny API isika ary hanome ohatra azo ampiharina maromaro. Fikirana CheckPoint mampiasa script.
Te hanao famandrihana avy hatrany aho fa ny API dia tsy ampiasaina afa-tsy amin'ny server Management. Ireo. Mbola tsy azo atao ny mitantana vavahady raha tsy misy mpizara Management.
Iza no afaka mampiasa ity API ity amin'ny ankapobeny?
- Mpitantana rafitra izay te hanatsotra na hanao automatique ny asa fanaon'ny Check Point mahazatra;
- Orinasa maniry ny hampiditra Check Point amin'ny vahaolana hafa (rafitra virtoaly, rafitra tapakila, rafitra fitantanana fanamafisana, sns.);
- Mpandrindra rafitra izay te hanara-penitra ny fikandrana na hamorona vokatra mifandraika amin'ny Check Point fanampiny.
Tetika mahazatra
Noho izany, andeha hojerentsika ny tetika mahazatra miaraka amin'ny Check Point:
Toy ny mahazatra dia manana vavahady izahay (SG), mpizara fitantanana (SMS) ary console admin (SmartConsole). Amin'ity tranga ity, ny fizotry ny fanamafisana vavahady mahazatra dia toy izao:
Ireo. Voalohany dia mila mihazakazaka amin'ny ordinateran'ny mpitantana ianao SmartConsole, izay mifandray amin'ny mpizara Management (SMS). Ny fametrahana ny fiarovana dia atao amin'ny SMS, ary avy eo dia ampiharina (fametrahana politika) mankany amin'ny vavahady (SG).
Rehefa mampiasa API fitantanana, azontsika atao ny mandingana ny teboka voalohany (manomboka SmartConsole) ary mampiasa baiko API mivantana amin'ny mpizara Management (SMS).
Fomba fampiasana ny API
Misy fomba efatra lehibe hanitsiana ny fanitsiana mampiasa ny API:
1) Mampiasa ny utility mgmt_cli
Ohatra - # mgmt_cli ampio ny anaran'ny mpampiantrano 1 ip-address 192.168.2.100
Ity baiko ity dia natomboka avy amin'ny baiko baiko Management Server (SMS). Heveriko fa mazava ny fehezan-teny amin'ny baiko - ny host1 dia noforonina miaraka amin'ny adiresy 192.168.2.100.
2) Ampidiro ny baiko API amin'ny alàlan'ny clish (amin'ny fomba matihanina)
Amin'ny ankapobeny, ny hany ilainao atao dia ny miditra amin'ny tsipika baiko (mgmt login) eo ambanin'ny kaonty ampiasaina rehefa mifandray amin'ny SmartConsole (na kaonty faka). Dia afaka miditra ianao baiko API (amin'ity tranga ity dia tsy ilaina ny mampiasa ny utility alohan'ny baiko tsirairay mgmt_cli). Afaka mamorona feno ianao script BASH. Ohatra iray amin'ny script iray noforonin'ny mpampiantrano:
Bash script
#!/bin/bash
main() {
clear
#LOGIN (don't ask for username and password, user is already logged in to Management server as 'root' user)
mgmt_cli login --root true > id_add_host.txt
on_error_print_and_exit "Error: Failed to login, check that the server is up and running (run 'api status')"
#READ HOST NAME
printf "Enter host name:n"
read -e host_name
on_empty_input_print_and_exit "$host_name" "Error: The host's name cannot be empty."
#READ IP ADDRESS
printf "nEnter host IP address:n"
read -e ip
on_empty_input_print_and_exit "$ip" "Error: The host's IP address cannot be empty."
#CREATE HOST
printf "Creating new host: $host_name with IP address: $ipn"
new_host_response=$(mgmt_cli add host name $host_name ip-address $ip -s id_add_host.txt 2> /dev/null)
on_error_print_and_exit "Error: Failed to create host object. n$new_host_response"
#PUBLISH THE CHANGES
printf "nPublishing the changesn"
mgmt_cli publish --root true -s id_add_host.txt &> /dev/null
on_error_print_and_exit "Error: Failed to publish the changes."
#LOGOUT
logout
printf "Done.n"
}
logout(){
mgmt_cli logout --root true -s id_add_host.txt &> /dev/null
}
on_error_print_and_exit(){
if [ $? -ne 0 ]; then
handle_error "$1"
fi
}
handle_error(){
printf "n$1n" #print error message
mgmt_cli discard --root true -s id_add_host.txt &> /dev/null
logout
exit 1
}
on_empty_input_print_and_exit(){
if [ -z "$1" ]; then
printf "$2n" #print error message
logout
exit 0
fi
}
# Script starts here. Call function "main".
main
Raha liana ianao dia afaka mijery ny video mifandraika amin'izany:
3) Amin'ny alàlan'ny SmartConsole amin'ny fanokafana ny varavarankely CLI
Ny hany ilainao dia manokatra ny varavarankely CLI mivantana avy SmartConsole, araka ny hita eo amin’ny sary etsy ambany.
Amin'ity varavarankely ity dia afaka manomboka miditra avy hatrany amin'ny baiko API ianao.
4) Serivisy Internet. Mampiasà HTTPS Post fangatahana (REST API)
Araka ny hevitray, izany no iray amin'ireo fomba mampanantena indrindra, satria mamela anao "hanorina" fampiharana manontolo mifototra amin'ny fitantanana fitantanana server (miala tsiny amin'ny tautologie). Eto ambany isika dia hijery ity fomba ity amin'ny antsipiriany bebe kokoa.
Raha fintinina:
- API + cli mety kokoa ho an'ny olona zatra Cisco;
- API + shell amin'ny fampiharana ny script sy ny fanatanterahana asa mahazatra;
- HAFA API ho an'ny automation.
Fampandehanana ny API
Amin'ny alàlan'ny default, ny API dia alefa amin'ny lohamilina fitantanana manana RAM mihoatra ny 4GB sy fanamafisana manokana miaraka amin'ny RAM mihoatra ny 8GB. Azonao atao ny manamarina ny sata amin'ny alàlan'ny baiko: sata api
Raha toa ka hita fa kilemaina ny api, dia mora ny mamela izany amin'ny alàlan'ny SmartConsole: Manage & Settings > Blades > Management API > Advanced Settings
Avy eo avoaka (Avoahy) manova ary mandehana ny baiko api restart.
Fangatahana tranonkala + Python
Mba hanatanterahana ny baiko API dia azonao ampiasaina ny fangatahana amin'ny Internet Python sy tranomboky fangatahana, json. Amin'ny ankapobeny, misy ampahany telo ny firafitry ny fangatahana tranonkala:
1) Adiresy
(https://<managemenet server>:<port>/web_api/<command>)
2) Lohatenin'ny HTTP
content-Type: application/json
x-chkp-sid: <session ID token as returned by the login command>
3) Mangataka entana
Lahatsoratra amin'ny endrika JSON misy ny masontsivana samihafa
Ohatra amin'ny fiantsoana baiko isan-karazany:
def api_call(ip_addr, port, command, json_payload, sid):
url = 'https://' + ip_addr + ':' + str(port) + '/web_api/' + command
if sid == “”:
request_headers = {'Content-Type' : 'application/json'}
else:
request_headers = {'Content-Type' : 'application/json', 'X-chkp-sid' : sid}
r = requests.post(url,data=json.dumps(json_payload), headers=request_headers,verify=False)
return r.json()
'xxx.xxx.xxx.xxx' -> Ip address GAIA
Ireto misy asa vitsivitsy mahazatra izay hitanao matetika rehefa mitantana ny Check Point.
1) Ohatra amin'ny asa fanomezan-dàlana sy fivoahana:
teny
payload = {‘user’: ‘your_user’, ‘password’ : ‘your_password’}
response = api_call('xxx.xxx.xxx.xxx', 443, 'login',payload, '')
return response["sid"]
response = api_call('xxx.xxx.xxx.xxx', 443,'logout', {} ,sid)
return response["message"]
2) Mandehana ny lelany sy mametraka ny tambajotra:
teny
new_gateway_data = {'name':'CPGleb','anti-bot':True,'anti-virus' : True,'application-control':True,'ips':True,'url-filtering':True,'interfaces':
[{'name':"eth0",'topology':'external','ipv4-address': 'xxx.xxx.xxx.xxx',"ipv4-network-mask": "255.255.255.0"},
{'name':"eth1",'topology':'internal','ipv4-address': 'xxx.xxx.xxx.xxx',"ipv4-network-mask": "255.255.255.0"}]}
new_gateway_result = api_call('xxx.xxx.xxx.xxx', 443,'set-simple-gateway', new_gateway_data ,sid)
print(json.dumps(new_gateway_result))
3) Fanovana ny fitsipiky ny firewall:
teny
new_access_data={'name':'Cleanup rule','layer':'Network','action':'Accept'}
new_access_result = api_call('xxx.xxx.xxx.xxx', 443,'set-access-rule', new_access_data ,sid)
print(json.dumps(new_access_result))
4) Manampy sosona fampiharana:
teny
add_access_layer_application={ 'name' : 'application123',"applications-and-url-filtering" : True,"firewall" : False}
add_access_layer_application_result = api_call('xxx.xxx.xxx.xxx', 443,'add-access-layer', add_access_layer_application ,sid)
print(json.dumps(add_access_layer_application_result))
set_package_layer={"name" : "Standard","access":True,"access-layers" : {"add" : [ { "name" : "application123","position" :2}]} ,"installation-targets" : "CPGleb"}
set_package_layer_result = api_call('xxx.xxx.xxx.xxx', 443,'set-package', set_package_layer ,sid)
print(json.dumps(set_package_layer_result))
5) Avoaka ary apetraho ny politika, jereo ny fanatanterahana ny baiko (task-id):
teny
publish_result = api_call('xxx.xxx.xxx.xxx', 443,"publish", {},sid)
print("publish result: " + json.dumps(publish_result))
new_policy = {'policy-package':'Standard','access':True,'targets':['CPGleb']}
new_policy_result = api_call('xxx.xxx.xxx.xxx', 443,'install-policy', new_policy ,sid)
print(json.dumps(new_policy_result)
task_id=(json.dumps(new_policy_result ["task-id"]))
len_str=len(task_id)
task_id=task_id[1:(len_str-1)]
show_task_id ={'task-id':(task_id)}
show_task=api_call('xxx.xxx.xxx.xxx',443,'show-task',show_task_id,sid)
print(json.dumps(show_task))
6) Ampio mpampiantrano:
teny
new_host_data = {'name':'JohnDoePc', 'ip-address': '192.168.0.10'}
new_host_result = api_call('xxx.xxx.xxx.xxx', 443,'add-host', new_host_data ,sid)
print(json.dumps(new_host_result))
7) Ampio saha Fisorohana ny Fandrahonana:
teny
set_package_layer={'name':'Standard','threat-prevention' :True,'installation-targets':'CPGleb'}
set_package_layer_result = api_call('xxx.xxx.xxx.xxx', 443,'set-package',set_package_layer,sid)
print(json.dumps(set_package_layer_result))
8) Jereo ny lisitry ny fivoriana
teny
new_session_data = {'limit':'50', 'offset':'0','details-level' : 'standard'}
new_session_result = api_call('xxx.xxx.xxx.xxx', 443,'show-sessions', new_session_data ,sid)
print(json.dumps(new_session_result))
9) Mamorona profil vaovao:
teny
add_threat_profile={'name':'Apeiron', "active-protections-performance-impact" : "low","active-protections-severity" : "low or above","confidence-level-medium" : "prevent",
"confidence-level-high" : "prevent", "threat-emulation" : True,"anti-virus" : True,"anti-bot" : True,"ips" : True,
"ips-settings" : { "newly-updated-protections" : "staging","exclude-protection-with-performance-impact" : True,"exclude-protection-with-performance-impact-mode" : "High or lower"},
"overrides" : [ {"protection" : "3Com Network Supervisor Directory Traversal","capture-packets" : True,"action" : "Prevent","track" : "Log"},
{"protection" : "7-Zip ARJ Archive Handling Buffer Overflow", "capture-packets" : True,"action" : "Prevent","track" : "Log"} ]}
add_threat_profile_result=api_call('xxx.xxx.xxx.xxx',443,'add-threat-profile',add_threat_profile,sid)
print(json.dumps(add_threat_profile_result))
10) Ovay ny hetsika ho an'ny sonia IPS:
teny
set_threat_protection={
"name" : "3Com Network Supervisor Directory Traversal",
"overrides" : [{ "profile" : "Apeiron","action" : "Detect","track" : "Log","capture-packets" : True},
{ "profile" : "Apeiron", "action" : "Detect", "track" : "Log", "capture-packets" : False} ]}
set_threat_protection_result=api_call('xxx.xxx.xxx.xxx',443,'set-threat-protection',set_threat_protection,sid)
print(json.dumps(set_threat_protection_result))
11) Ampio ny serivisinao:
teny
add_service_udp={ "name" : "Dota2_udp", "port" : '27000-27030',
"keep-connections-open-after-policy-installation" : False,
"session-timeout" : 0, "match-for-any" : True,
"sync-connections-on-cluster" : True,
"aggressive-aging" : {"enable" : True, "timeout" : 360,"use-default-timeout" : False },
"accept-replies" : False}
add_service_udp_results=api_call('xxx.xxx.xxx.xxx',443,"add-service-udp",add_service_udp,sid)
print(json.dumps(add_service_udp_results))
12) Manampia sokajy, tranokala na vondrona:
teny
add_application_site_category={ "name" : "Valve","description" : "Valve Games"}
add_application_site_category_results=api_call('xxx.xxx.xxx.xxx',443,"add-application-site-category",add_application_site_category,sid)
print(json.dumps(add_application_site_category_results))
add_application_site={ "name" : "Dota2", "primary-category" : "Valve", "description" : "Dotka",
"url-list" : [ "www.dota2.ru" ], "urls-defined-as-regular-expression" : False}
add_application_site_results=api_call('xxx.xxx.xxx.xxx',443,"add-application-site " ,
add_application_site , sid)
print(json.dumps(add_application_site_results))
add_application_site_group={"name" : "Games","members" : [ "Dota2"]}
add_application_site_group_results=api_call('xxx.xxx.xxx.xxx',443,"add-application-site-group",add_application_site_group,sid)
print(json.dumps(add_application_site_group_results))
Ankoatra izany, miaraka amin'ny fanampiana WebAPI azonao atao ny manampy sy manaisotra tambajotra, mpampiantrano, andraikitry ny fidirana, sns. Blades azo namboarina Antivirus, Antibot, IPS, VPN. Azo atao mihitsy aza ny mametraka lisansa mampiasa ny baiko run-script. Ny baiko Check Point API rehetra dia hita eto
Check Point API + Postman
Mora ampiasaina koa Check Point Web API miaraka amin'ny
Amin'ny fampiasana an'io fitaovana io, dia afaka mamorona fangatahana amin'ny Internet amin'ny Check Point API isika. Mba tsy hahatsiarovana ny baiko API rehetra dia azo atao ny manafatra ireo antsoina hoe fanangonana (templates), izay efa misy ny baiko ilaina rehetra:
Raha ny hevitro dia tena mety izany. Afaka manomboka mamolavola fampiharana haingana ianao amin'ny alàlan'ny Check Point API.
Check Point + Ansible
Tiako koa ny manamarika fa misy Ansible
famaranana
Eto no mety hamaranantsika ny famerenana fohy momba ny Check Point API. Raha ny hevitro dia efa nandrasana hatry ny ela io endri-javatra io ary ilaina. Ny firongatry ny API dia manokatra fahafahana be dia be ho an'ny mpitantana ny rafitra sy ny mpandrindra rafitra izay miasa amin'ny vokatra Check Point. Orkestra, automatique, feedback SIEM... azo atao daholo izao.
PS Lahatsoratra bebe kokoa momba ny
PSS Ho an'ny fanontaniana ara-teknika mifandraika amin'ny fametrahana Check Point dia azonao atao
Ireo mpampiasa voasoratra anarana ihany no afaka mandray anjara amin'ny fanadihadiana.
Mikasa ny hampiasa ny API ve ianao?
-
70,6%Eny12
-
23,5%No4
-
5,9%Efa mampiasa1
Mpampiasa 17 no nifidy. Mpampiasa 3 no nifady.
Source: www.habr.com