How to add naxsi rules by api?

Started by akong77, November 03, 2020, 03:38:40 AM

Previous topic - Next topic
Hello,
I use follow command to create naxsi rules

Quotecurl -XPOST -d '{"naxsi_rule":{"description":"test_rules","ruletype":{"main":{"5000":"Main Rule","selected":1}}"message":"test_123","matchType: application/json" -k -u "key":"secret" https://IP:8082/api/nginx/addnaxsirule

But it's will get error message.

Quote{"message":"controller OPNsense\\Nginx\\Api\\AddnaxsiruleController not found","status":400}

Is it my path is wrong?

November 03, 2020, 04:28:11 AM #1 Last Edit: November 03, 2020, 05:12:22 AM by akong77
I found lose some path. I fix it.
But please help me
Quotecurl -XPOST -d '{"naxsi_rule":{"description":"doc file upload","ruletype":{"main":{"value":"Main Rule","selected":1},"basic":{"value":"Basic Rule","selected":0}},"message":"doc file upload","identifier":"2500","url":"0","dollar_url":"","match_value":"\\.doc","match_type":{"id":{"value":"Blacklist","selected":1},"wl":{"value":"Whitelist","selected":0}},"negate":"0","score":"8","regex":"1","args":"0","headers":"0","dollar_args_var":"","dollar_body_var":"","dollar_headers_var":"","file_extension":"1","raw_body":"0","name":"0"}}' -H "Content-Type: application/json" -k -u "key":"secure" https://IP:8082/api/nginx/settings/addnaxsirule

I want post new add rules.I use this command to post it.I got error message.

Quote{"errorMessage":"Error at /usr/local/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php:334 - Array to string conversion (errno=8)","errorTitle":"An API exception occured"}

Where setup is wrong?

Check via browser how it works and compare to yours. Also worth checking configd.log

I use follow command to get already rules.

`curl -k -u "key":"secret" https://IP:8082/api/nginx/settings/getnaxsirule/7b7bacfe-ee9a-46e6-b5cd-00176a33f1e3`

I got follow content.

`{"naxsi_rule":{"description":"asp\/php\/jsp file upload","ruletype":{"main":{"value":"Main Rule","selected":1},"basic":{"value":"Basic Rule","selected":0}},"message":"asp\/php\/jsp file upload","identifier":"1500","url":"0","dollar_url":"","match_value":"\\.ph|\\.asp|\\.ht|\\.jsp","match_type":{"id":{"value":"Blacklist","selected":1},"wl":{"value":"Whitelist","selected":0}},"negate":"0","score":"8","regex":"1","args":"0","headers":"0","dollar_args_var":"","dollar_body_var":"","dollar_headers_var":"","file_extension":"1","raw_body":"0","name":"0"}}`

I copy this rules and edit some settings like description and identifier and message and match_value.Then I use follow command to add rules.

`curl -XPOST -d '{"naxsi_rule":{"description":"doc file upload","ruletype":{"main":{"value":"Main Rule","selected":1},"basic":{"value":"Basic Rule","selected":0}},"message":"doc file upload","identifier":"2500","url":"0","dollar_url":"","match_value":"\\.doc","match_type":{"id":{"value":"Blacklist","selected":1},"wl":{"value":"Whitelist","selected":0}},"negate":"0","score":"8","regex":"1","args":"0","headers":"0","dollar_args_var":"","dollar_body_var":"","dollar_headers_var":"","file_extension":"1","raw_body":"0","name":"0"}}' -H "Content-Type: application/json" -k -u "key":"secret" https://IP:8082/api/nginx/settings/addnaxsirule`

It's will get error message.Could I make a mistake something?

Please, dont use Forum AND GitHub .. not easy to track



Hit F12 in browser, network tab, add a naxsi rule via browser and look at the correct syntax of your browser

@akong77
can you please be more spesific? what was the source of error?