rengine icon indicating copy to clipboard operation
rengine copied to clipboard

bug: CIDR resolutions on Targets tab not working

Open d4op opened this issue 7 months ago • 9 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Current Behavior

if use add target, switch to tab resolive and add ip address there is an input ip addresss or CIDR

  • 1 IP works
  • CIDR doesnt work!

Expected Behavior

if use add target, switch to tab resolive and add ip address there is an input ip addresss or CIDR

  • 1 IP works
  • CIDR doesnt work!

Steps To Reproduce

if use add target, switch to tab resolive and add ip address there is an input ip addresss or CIDR

  • 1 IP works
  • CIDR doesnt work!

Environment

- reNgine: latest

Anything else?

No response

d4op avatar Jan 10 '24 20:01 d4op

👋 Hi @d4op, Issues is only for reporting a bug/feature request. Please read documentation before raising an issue https://rengine.wiki For very limited support, questions, and discussions, please join reNgine Discord channel: https://discord.gg/azv6fzhNCE Please include all the requested and relevant information when opening a bug report. Improper reports will be closed without any response.

github-actions[bot] avatar Jan 10 '24 20:01 github-actions[bot]

Thanks for reporting. I will have a look

psyray avatar Jan 12 '24 00:01 psyray

I'm also experiencing this issue. There may be multiple issues here; I'm continuing to investigate. The first thing I've noticed is that CIDR blocks are not expanded before socket.gethostbyaddr() is called during API call to /api/tools/ip_to_domain/?format=json&ip_address=X.X.X.X/Y

The code is here: https://github.com/yogeshojha/rengine/blob/000b116173137e429faf269f96ce4f94cb2b7324/web/api/views.py#L1087

This API call is made from the "Resolve and add IP Address" tab of the "Add Target" page. This tab explicitly states CIDR blocks are supported as input.

pbehnke avatar Feb 21 '24 20:02 pbehnke

There is a second issue when adding CIDR blocks via the "Add Targets" tab (i.e. where newline delimited domains are entered). The issue is due to the reuse of a variable name ("ips") defined here: https://github.com/yogeshojha/rengine/blob/2e903ac4a9bfe85bd4677de400e7bdfa4fffc4fe/web/targetApp/views.py#L97 and additionally on line 60: https://github.com/yogeshojha/rengine/blob/2e903ac4a9bfe85bd4677de400e7bdfa4fffc4fe/web/targetApp/views.py#L60

You're getting a list of IPs from get_ips_from_cidr_range() on line 95 and storing them in a list called "ips", then you're looping through that list and appending each IP to a different list also called "ips" defined on line 60. However, because of the name clash, you're actually appending each IP back onto the list on line 95. This results in an infinite loop and memory leak. The variable on line 95 should be called something else. I can submit a PR if desired.

@psyray

pbehnke avatar Feb 22 '24 00:02 pbehnke

Is it possible for you to provide a PR to fix this issue ?

psyray avatar Feb 22 '24 07:02 psyray

Sure. I have a fix ready for the second issue. The first issue is a bit more involved and I'm not really a javascript person but I can take a stab at it.

pbehnke avatar Feb 22 '24 20:02 pbehnke

I've fixed both the issues above, but there's another issue when adding IPs on the "Resolve and add IP Address" where it errors out stating the target is already in the database. I'll dig into that and then create the PR once it's all working. Please feel free to look at the commits outlined above and provide any feedback in the meantime

pbehnke avatar Feb 22 '24 21:02 pbehnke

@psyray - I created https://github.com/yogeshojha/rengine/pull/1205 to fix these issues. Let me know if you have any comments or questions! I have these changes running locally and they all appear to work as expected.

pbehnke avatar Feb 26 '24 22:02 pbehnke

Thx I will check this

psyray avatar Feb 28 '24 17:02 psyray

Closed. Fix on #1205

yogeshojha avatar Jul 20 '24 07:07 yogeshojha