jokob-sk / NetAlertX

💻🔍 WIFI / LAN intruder detector. Scans for devices connected to your network and alerts you if new and unknown devices are found.
GNU General Public License v3.0
1.93k stars 97 forks source link

Configuring SNMP on pfsense #718

Open iptvcld opened 5 days ago

iptvcld commented 5 days ago

Is there an existing issue for this?

Am I willing to test this? 🧪

Can I help implement this? 👩‍💻👨‍💻

Is your feature request related to a problem? Please describe

If a device connects and then disconnects then we won’t be alerted of the scan does not occur

Describe the solution you'd like

Real time scan maybe look at dhcp logs of pfsense

Describe alternatives you've considered

Warpath

Anything else?

No

jokob-sk commented 5 days ago

Hi @iptvcld ,

You can already adjust the scan window to be e.g. every minute via Settings. If taht's insufficient, you can try is to create a custom plugin to continuously scan in a separate thread and the results would be then processed in given intervals.

This way you would never miss a device. Disconnections may still be missed (if a device disconnects and reconnects, let's say within a minute), but I think discovering of new devices is more important.

If you are happy to help out, I can try incorporating continuous scanning, why you try to create a pfsense plugin, if you have some time. Here is a walkthrough of creating a custom plugin: Watch the video

🎥Watch the video

jokob-sk commented 5 days ago

Actually - I just realized SNMP is supported on pfsense, so you can try the SNMP plugin if it already works. If yes, and the 1 minute interval is still too long, I can try to incorporate continuous background scanning. Let me know how you go.

iptvcld commented 5 days ago

Thanks for the reply. I can try snmp but I think continuously scanning may get in the way of pfsense internal scans that occur. But I am not sure what pfsense sends for snmp dhcp responses because let’s say I have the scan at 5 mins can this tool check past connections and then just alert on any new connects. I don’t need instant but just something that tells me some device connected and it may be not be online but I have a record of it

jokob-sk commented 5 days ago

This then depends on what information is available via SNMP. If past entries are, then yes 👍

iptvcld commented 5 days ago

And will this tool know how to read the Mac and IP and format the notification?

jokob-sk commented 5 days ago

yes :)

iptvcld commented 5 days ago

I just enabled SNMP on pfsense and then enabled the option on netalertX and updated the iP to my router - but no devices are being found

22:09:22 [2024-07-01 22:09:22-04:00] START Run: SNMPDSC 22:09:22 [Plugins] Executing: python3 /app/front/plugins/snmp_discovery/script.py routers={s-quote}{routers}{s-quote} 22:09:22 [SNMPDSC] In script 22:09:22 [SNMPDSC] Router snmpwalk command: snmpwalk -v 2c -c public -OXsq 192.168.2.80 .1.3.6.1.2.1.3.1.1.2 22:09:22 [SNMPDSC] output: mib-2.3.1.1.2 No Such Object available on this agent at this OID

22:09:22 [SNMPDSC] Entries found: 0 22:09:22 [Plugins] No output received from the plugin SNMPDSC - enable LOG_LEVEL=debug and check logs 22:09:22 [2024-07-01 22:09:22-04:00] END Run: SNMPDSC

jokob-sk commented 5 days ago

Hi!

I think this is not an issue with NetAlertX, but with the command or agent configuration. This is what I got out of ChatGPT:

The "No Such Object available on this agent at this OID" error in SNMP usually means that the specific OID (Object Identifier) you are querying does not exist or is not available on the SNMP agent you are querying.

Here are a few steps to troubleshoot this issue:

Verify the OID:
    Make sure that the OID you are querying is correct and exists on the SNMP agent. Double-check the documentation for the device or software you are querying.

SNMP Version Compatibility:
    Ensure that the SNMP version you are using (SNMPv1, SNMPv2c, SNMPv3) is supported by the agent and that you are using the correct version in your query.

Access Control:
    Check the SNMP access control settings on the agent. It might be configured to restrict access to certain OIDs based on community strings or user credentials.
    For SNMPv3, ensure that the user has the necessary permissions to access the OID.

MIBs:
    Make sure you have the correct MIBs (Management Information Bases) loaded that define the OIDs. Without the correct MIBs, your SNMP tools may not be able to resolve OIDs properly.

SNMP Walk:
    Perform an SNMP walk starting from a higher-level OID to see what OIDs are available on the agent. This can help you identify if the OID you are querying is indeed present.
    Example command using snmpwalk:

    sh

    snmpwalk -v2c -c public 192.168.1.1 .1

Agent Configuration:
    Ensure the SNMP agent is properly configured to expose the OIDs you are trying to query. This might involve editing the SNMP configuration file on the device.

Check Logs:
    Check the SNMP agent's logs for any error messages or indications of why the OID is not available.

Here is an example of querying an SNMP agent with snmpget:

sh

snmpget -v2c -c public 192.168.1.1 .1.3.6.1.2.1.1.1.0

Replace public with your community string, 192.168.1.1 with the IP address of your SNMP agent, and .1.3.6.1.2.1.1.1.0 with your target OID.

jokob-sk commented 5 days ago

Here is the chat history if you'd like to follow up: https://chatgpt.com/share/4f43da10-f66e-40f8-a10d-50b245b9f12d

iptvcld commented 5 days ago

Thanks; i have enabled it pfsense correct and on netalertX - i have enabled SNMP, updated the IP for the walk and ran the scan - but nothing. Maybe something to do with auth to pfsense, there are no fields for the username and password

jokob-sk commented 5 days ago

you can also ssh into the container or any terminal and try if your command works - I regrettably don't have pfsense running, but try to troubleshoot with that chatgpt instance and if you get the command running in the terminal, you should be able to use it in netalertx

iptvcld commented 5 days ago

ok, i will have a chat with GPT - this is the result using terminal c9f5de0051e7:/# snmpget -v2c -c public 192.168.2.80 .1.3.6.1.2.1.1.1.0 SNMPv2-MIB::sysDescr.0 = STRING: pfSense pfadmin.servernode.com 2.7.2-RELEASE FreeBSD 14.0-CURRENT amd64

jokob-sk commented 5 days ago

as per the docs, the expected output should look something like this for NAX to ingest it properly:

Expected output (ingestion) in format:

 iso.3.6.1.2.1.3.1.1.2.3.1.192.168.1.2 "6C 6C 6C 6C 6C 6C "
 iso.3.6.1.3.1.3.1.1.2.3.1.192.168.1.3 "7C 6C 6C 6C 6C 6C "
 iso.3.6.1.4.1.3.1.1.2.3.1.192.168.1.4 "8C 6C 6C 6C 6C 6C "
...etc
iptvcld commented 5 days ago

ok so this snmpwalk -v2c -c public 192.168.2.80 1.3.6.1.2.1.4.22.1.2 returned

IP-MIB::ipNetToMediaPhysAddress.15.192.168.2.2 = STRING: 48:b0:2d:32:a4:4a IP-MIB::ipNetToMediaPhysAddress.15.192.168.2.3 = STRING: a2:e5:bc:85:11:f6

i added this command into the SNMP scan in netalert but after the run, no devices get added

jokob-sk commented 5 days ago

Taht's not a format NAX understands, as mentioned earlier, the only supported format for SNMP outputs is this one:

 iso.3.6.1.2.1.3.1.1.2.3.1.192.168.1.2 "6C 6C 6C 6C 6C 6C "
 iso.3.6.1.3.1.3.1.1.2.3.1.192.168.1.3 "7C 6C 6C 6C 6C 6C "
 iso.3.6.1.4.1.3.1.1.2.3.1.192.168.1.4 "8C 6C 6C 6C 6C 6C "

PLease use the appropriate parameters to format your output according to the docs:

sh

snmpwalk -v2c -c public -OXsq 192.168.1.1 .1.3.6.1.2.1.3.1.1.2

-v2c: Specifies the SNMP version to use (SNMPv2c in this case).
-c public: Specifies the community string (password-like value used for SNMP, public is the default community string).
-OXsq: Specifies output formatting options:
    -O: Specifies how the output should be formatted.
    X: Prints the OID in numeric form (ISO-style).
    s: Strips the OID labels from the output.
    q: Suppresses the display of the type of data.
iptvcld commented 5 days ago

When i run snmpwalk -v2c -c public -OXsq 192.168.2.80 .1.3.6.1.2.1.3.1.1.2 - i then get this mib-2.3.1.1.2 No Such Object available on this agent at this OID

that command seems like does not work on pfsense, so net alert needs this exact layout? iso.3.6.1.2.1.3.1.1.2.3.1.192.168.1.2 "6C 6C 6C 6C 6C 6C " (with the iso in front, etc )

jokob-sk commented 5 days ago

pfsense shoulw work if you supply the correct command. Here is a past issue where another user uses the same plugin with pfsense: https://github.com/jokob-sk/NetAlertX/issues/258

iptvcld commented 5 days ago

ahh soo odd.. snmpwalk -v 2c -c public -OXsq 192.168.2.1 .1.3.6.1.2.1.4.22.1.2 gives me: ipNetToMediaPhysAddress[15][192.168.2.191] 3c:39:c8:e5:fd:84

jokob-sk commented 5 days ago

The key part you have to figure out is the OID. I don't think you have the correct OID .1.3.6.1.2.1.4.22.1.2. This OID changes based for example on the manufacturer. Some hints follow:

Understand the OID Structure:

Break Down the OID .1.3.6.1.2.1.4.22.1:

Consult SNMP MIB Documentation:

Please check this article for details: https://www.comparitech.com/net-admin/snmpwalk-examples-windows-linux/ You can find manufacturer IDs here: https://www.iana.org/assignments/enterprise-numbers/

jokob-sk commented 5 days ago

I made the SNMP plugin accept also ipNetToMediaPhysAddress output and I wrote a guide on it here:

https://github.com/jokob-sk/NetAlertX/tree/main/front/plugins/snmp_discovery#finding-your-oid

image

Please have a look at the netalertx-dev docker image, in about 15 minutes (or after the last action finishes) from now.

Make sure you refresh your browser cache - and click the 🔄 refresh button in the top right corner.

It would be great if you could test this (backup everything first or use a new container) on your end by switching to the above image and letting me know if the issue was resolved/the new feature is working.

Thanks in advance, j

iptvcld commented 4 days ago

Wow you’re amazing! I had to leave town for work and will be back tomorrow evening to test this out. Can’t wait! Thank you.

iptvcld commented 3 days ago

Hey @jokob-sk just changed docker to -dev and added snmpwalk -v 2c -OXsq -c public 192.168.2.1 .1.3.6.1.2.1.4.22.1.2 to the SNMP section but below is the error.

07:07:16 [Plugin utils] ---------------------------------------------
07:07:16 [Plugin utils] display_name: SNMP discovery
07:07:16 [Plugins] Executing: python3 /app/front/plugins/snmp_discovery/script.py routers={s-quote}{routers}{s-quote}
07:07:16 [SNMPDSC] In script 
07:07:16 [SNMPDSC] Router snmpwalk command: snmpwalk -v 2c -OXsq  -c public 192.168.2.1 .1.3.6.1.2.1.4.22.1.2
07:07:16 [plugin_helper] reading config file
07:07:16 [SNMPDSC] In script 
07:07:16 [SNMPDSC] Router snmpwalk command: snmpwalk -v 2c -OXsq  -c public 192.168.2.1 .1.3.6.1.2.1.4.22.1.2
Traceback (most recent call last):
  File "/app/front/plugins/snmp_discovery/script.py", line 115, in <module>
    main()
  File "/app/front/plugins/snmp_discovery/script.py", line 55, in main
    output = subprocess.check_output (snmpwalkArgs, universal_newlines=True, stderr=subprocess.STDOUT, timeout=(timeoutSec ))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/subprocess.py", line 466, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['snmpwalk', '-v', '2c', '-OXsq', '', '-c', 'public', '192.168.2.1', '.1.3.6.1.2.1.4.22.1.2']' returned non-zero exit status 1.

07:07:16 [Plugins] ⚠ ERROR - enable LOG_LEVEL=debug and check logs
07:07:16 [Plugins] No output received from the plugin SNMPDSC - enable LOG_LEVEL=debug and check logs
07:07:16 [API] Updating table_plugins_language_strings.json file in /front/api
07:07:16 [Plugin utils] ---------------------------------------------
07:07:16 [Plugin utils] display_name: NSLOOKUP (Name discovery)
07:07:16 [Plugins] Executing: python3 /app/front/plugins/nslookup_scan/nslookup.py
07:07:16 [NSLOOKUP] In script
07:07:16 [Database] Opening DB
07:07:16 [NSLOOKUP] Unknown devices count: 0
07:07:16 [NSLOOKUP] Script finished
07:07:16 [Plugins] No output received from the plugin NSLOOKUP - enable LOG_LEVEL=debug and check logs
07:07:16 [Notification] Check if something to report
07:07:16 [Notification] Included sections: ['new_devices', 'down_devices', 'events']
07:07:16 [Notification] No changes to report
07:07:16 [MAIN] Process: Wait

via console this is my output (Sample)

ipNetToMediaPhysAddress[15][192.168.2.7] bc:24:11:44:b6:53
ipNetToMediaPhysAddress[15][192.168.2.9] c4:c1:7d:cf:bf:33
jokob-sk commented 3 days ago

Thanks for checking. I just pushed a fix to the -dev image. It should be available in about 15 minutes. Please check if the issue was fixed.

iptvcld commented 2 days ago

Works like a charm! Thank you, I can see the snmpwalk listing all the connections and then the lookup grabs the names of the devices (for most). I added a new device to my network and ran the snmp scan again, it picked up the new device!

When do you think this will be promoted to Prod? I will then start working on my setup and get telegram going as well! Thanks again..

jokob-sk commented 2 days ago

thanks for checking @iptvcld !

I might publish the prod image this weekend or next week. 🤞

iptvcld commented 2 days ago

Thanks again, looking forward to it..