How to configure engine ID to send SNMP trap V3 using SNMP4J? - net-snmp

I'm using snmp4j 2.8.4 and Java 1.8
It works when I use the command line to send traps.for example
snmptrapd.conf
authCommunity log,execute,net public
createUser -e 0x8000000001020304 myuser MD5 mypassword DES mypassword1
authUser log,execute,net myuser noauth
The command is
snmptrap -e 0x8000000001020304 -v 3 -u myuser -a MD5 -A myjjpassword -x DES -X myjjpassword1 -l noAuthNoPriv 192.168.135.18:162 "" 1.3.6.1.4.1.48183 1.3.6.1.4.1.48183.1 s "smartmon"
It was ok at this point, but when I used SNMP4J, I didn't know if my engine ID was not set up correctly, which caused the trap failure or some other reason
USM usm = new USM(SecurityProtocols.getInstance(), localEngineID, 0);
SecurityModels.getInstance().addSecurityModel(usm);
usm.updateUser(new UsmUserEntry(new OctetString("myuser"),
new OctetString("0x8000000001020304".getBytes()), new UsmUser(new OctetString("myuser"),
null,
null,
null,
null)));
snmp = new Snmp(transport);
snmp.setLocalEngine(new OctetString("0x8000000001020304".getBytes()).getValue(),0,0);
snmp.getMessageDispatcher().addMessageProcessingModel(new MPv3(usm));
transport.listen();
Could you tell me where I have a problem setting?How should I set the Engine ID?Thank you very much for your answers

OctetString uses a different string representation than NET-SNMP does. Thus, you need to specify your engine ID as:
OctetString.fromString("8000000001020304", 16);

Related

How to create solr password hash

From solr documentation to create a user I need to add following lines to security.json config file:
"authentication":{
"class":"solr.BasicAuthPlugin",
"credentials":{
"solr":"IV0EHq1OnNrj6gvRCwvFwTrZ1+z1oBbnQdiVC3otuq0= Ndd7LKvVBAaZIF0QAVi1ekCfAJXr1GGfLtRUXhgrF8c="
}
},
I know that under authentication.credentials the key solr is the username and value IV0EHq1OnNrj6gvRCwvFwTrZ1+z1oBbnQdiVC3otuq0= Ndd7LKvVBAaZIF0QAVi1ekCfAJXr1GGfLtRUXhgrF8c= is the hash of password SolrRocks.
But my question is, how can I generate that hash?
The documentation does not mention it anywhere,
It does not look like md5, sha1, argon nor any hash known to me.
After decoding the base64 it seems to be stored as some binary data.
What kind of hash is that, and how can I create it from bash?
You'd usually use set-user in the Authentication API to add the user.
rmalchow on GitHub has created a standalone version for bash:
#!/bin/bash
PW=$1
SALT=$(pwgen 48 -1)
echo "hash : $(echo -n "$SALT$PW" | sha256sum -b | xxd -r -p | sha256sum -b | xxd -r -p | base64 -w 1024) $(echo -n "$SALT" | base64 -w1024)"

Camel route SNMP Trap route - No response for V3 traps

I am new in Camel, trying to create a SNMP Camel route
from("snmp:0.0.0.0:162?protocol=udp&type=TRAP&securityName="
+ new OctetString("MD5DES")+"&snmpVersion="+SnmpConstants.version3+"&securityLevel="
+SecurityLevel.AUTH_PRIV+"&authenticationPassphrase="+snmpuser +
"privacyPassphrase=" + snmppass
+ "&authenticationProtocol=MD5&privacyProtocol=DES").log("{body}");
Once the route is started, I can send snmp Trap from snmptrap commnad for Version V1 and V2 and do not get any auth error and traps are received in the code and printed , but when I send V3 trap from snmptrap command, it shows success on sender side , but nothing is received on Camel code.
snmptrap -v 3 -u user -a MD5 -A password -x DES -X password -l 3 127.0.0.1 '' 1.3.6.1.4.1.8072.2.3.0.1 1.3.6.1.4.1.8072.2.3.2.1 i 12335
Appreciate any help.

Using Secrets API with dbus-send

I'm trying to figure out how to get a password from the keyring using dbus-send, but I'm struggling to understand what the session parameter is.
Here's where I've got to:
#!/bin/bash
# Find key path
KEY_PATH=$(dbus-send --dest=org.freedesktop.secrets --print-reply=literal /org/freedesktop/secrets org.freedesktop.Secret.Service.SearchItems dict:string:string:"mount-point","/home/s/.mozilla/firefox" | grep -Eo '/\S+')
# Unlock keyring
RESULT=$(dbus-send --dest=org.freedesktop.secrets --print-reply=literal /org/freedesktop/secrets org.freedesktop.Secret.Service.Unlock array:objpath:$KEY_PATH | grep -Eo '/\S+')
# If unlocked...
if [ "$RESULT" = "$KEY_PATH" ]; then
# Get password
PASSWORD=$(dbus-send --dest=org.freedesktop.secrets --print-reply=literal /org/freedesktop/secrets org.freedesktop.Secret.Service.GetSecrets array:objpath:$KEY_PATH objpath:<WHAT IS SESSION?>)
# Mount ecryptfs firefox directory
echo $PASSWORD | ecryptfs-simple -o key=passphrase,ecryptfs_cipher=aes,ecryptfs_key_bytes=32,ecryptfs_passthrough=no,ecryptfs_enable_filename_crypto=yes,no_sig_cache=yes /home/s/.mozilla/.firefox-ecryptfs /home/s/.mozilla/firefox
firefox $#
fi
I'm lost as to how to get a session to fetch the password.
The session needs to be created using:
org.freedesktop.Secret.Service.OpenSession (
IN String algorithm,
IN Variant input,
OUT Variant output,
OUT ObjectPath result);
https://specifications.freedesktop.org/secret-service/latest/re01.html
Here is an example of creating a non-encrypted session. Be aware the password returned by GetSecret will be a plain text as it uses a non-encrypted session:
dbus-send --dest=org.freedesktop.secrets --print-reply=literal /org/freedesktop/secrets org.freedesktop.Secret.Service.OpenSession string:plain variant:string:''
The output is the objpath to the created session:
variant /org/freedesktop/secrets/session/s31
Then, theoretically, you can pass the session to GetSecrets. For example:
dbus-send --dest=org.freedesktop.secrets --print-reply=literal /org/freedesktop/secrets org.freedesktop.Secret.Service.GetSecrets array:objpath:/org/freedesktop/secrets/collection/login/6 objpath:/org/freedesktop/secrets/session/s31
Note: /org/freedesktop/secrets/collection/login/6 is the object path returned by SearchItems.
However, this does not work with dbus-send. I think this is because the session is likely closed as soon as dbus-send returns.
If you use d-feet, the session is retained until the d-feet window is closed. So, you will be able to get the password using d-feet though. But, I understood that you want to automate it.
I suggest you use python3's keyring which offers to get a password using an encrypted session.

How can I send messages directly to a group?

I need help sending text to a particular group using the adb shell.
Searching the forums here, I found the code below:
adb shell am start -n com.whatsapp/.Main
adb shell am start -a android.intent.action.SEND -t text/plain -e jid
'xxxxxxxxxxx#s.whatsapp.net' --eu android.intent.extra.STREAM
file:///storage/emulated/0/DCIM/Camera/IMG_20181025_223214.jpg -p com.whatsapp
the question is:
How to identify a group's JID.
How to change this code to send a text instead of a file.
Groups jid you can get in messages.db at chat_list table by gorup name (subject column) or at messages table by message text. it will be like 77787987018-1602484814#g.us.
To send text u can use this command:
am start -a android.intent.action.SEND -c android.intent.category.DEFAULT -t text/plain -e jid {user jid} -e android.intent.extra.TEXT "{text}" -p {whatsapp packet name}

PostgreSQL \lo_import and how to get the resulting OID into an UPDATE command?

I'm working with Postgres 9.0, and I have an application where I need to insert images into the remote server. So I use:
"C:\Program Files\PostgreSQL\9.0\bin\psql.exe" -h 192.168.1.12 -p 5432 -d myDB -U my_admin -c "\lo_import 'C://im/zzz4.jpg'";
where
192.168.1.12 is the IP address of the server system
5432 is the Port number
myDB is server database name
my_admin is the username
"\lo_import 'C://im/zzz4.jpg'" is the query that is fired.
After the image has been inserted into the database I need to update a row in a table like this:
UPDATE species
SET speciesimages=17755; -- OID from previous command.. how to get the OID ??
WHERE species='ACCOAA';
So my question is: how do I get the OID returned after the \lo_import in psql?
I tried running \lo_import 'C://im/zzz4.jpg' in Postgres but I get an error:
ERROR: syntax error at or near ""\lo_import 'C://im/zzz4.jpg'""
LINE 1: "\lo_import 'C://im/zzz4.jpg'"
I also tried this:
update species
set speciesimages=\lo_import 'C://im/zzz4.jpg'
where species='ACAAC04';
But I get this error:
ERROR: syntax error at or near "\"
LINE 2: set speciesimages=\lo_import 'C://im/zzz4.jpg'
^
As your file resides on your local machine and you want to import the blob to a remote server, you have two options:
1) Transfer the file to the server and use the server-side function:
UPDATE species
SET speciesimages = lo_import('/path/to/server-local/file/zzz4.jpg')
WHERE species = 'ACAAC04';
2) Use the psql meta-command like you have it.
But you cannot mix psql meta commands with SQL-commands, that's impossible.
Use the psql variable :LASTOID in an UPDATE command that you launch immediately after the \lo_import meta command in the same psql session:
UPDATE species
SET speciesimages = :LASTOID
WHERE species = 'ACAAC04';
To script that (works in Linux, I am not familiar with Windows shell scripting):
echo "\lo_import '/path/to/my/file/zzz4.jpg' \\\\ UPDATE species SET speciesimages = :LASTOID WHERE species = 'ACAAC04';" | \
psql -h 192.168.1.12 -p 5432 -d myDB -U my_admin
\\ is the separator meta-command. You need to double the \, in a "" string, because the shell interprets one layer.
\ before the newline is just the line continuation in Linux shells.
Alternative syntax (tested on Linux again):
psql -h 192.168.1.12 -p 5432 -d myDB -U my_admin << EOF
\lo_import '/path/to/my/file/zzz4.jpg'
UPDATE species
SET speciesimages = :LASTOID
WHERE species = 'ACAAC04';
EOF
After importing an image with this command:
\lo_import '$imagePath' '$imageName'
You can then find the description of the binary by querying the pg_catalog.pg_largeobject_metadata table which stores the oid value you need.
Ie:
"SELECT oid as `"ID`",
pg_catalog.obj_description(oid, 'pg_largeobject') as `"Description`"
FROM pg_catalog.pg_largeobject_metadata WHERE pg_catalog.obj_description(oid,'pg_largeobject') = '$image' limit 1 "
Here's how to do it if your field is type bytea.
\lo_import '/cygdrive/c/Users/Chloe/Downloads/Contract.pdf'
update contracts set contract = lo_get(:LASTOID) where id = 77;
Use \lo_list and \lo_unlink after you import.

Resources