pysnmp: How to send a trap with time of trigger information - pysnmp

I am using pysnmp to generate v3 traps
How should to send time of trigger information with the trap

You could probably use the sysUpTime object to convey the SNMP system uptime information.
Alternatively, you could a special custom OID dedicated for carrying time information (add it via .addVarBinds()).
from pysnmp.hlapi import *
errorIndication, errorStatus, errorIndex, varBinds = next(
sendNotification(
SnmpEngine(),
UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
UdpTransportTarget(('demo.snmplabs.com', 162)),
ContextData(),
'trap',
NotificationType(
# your trap type
ObjectIdentity('1.3.6.1.6.3.1.1.5.2')
).addVarBinds(
# sysUpTime in hundredths of a second
ObjectType(ObjectIdentity('1.3.6.1.2.1.1.3.0'), 123456)
)
)
)

Related

Perl Module Net::DNS - calling "tsig" method on resolver object results in error

recently the linux-distribution i use (recent gentoo)
upgraded the net-dns package to version 0.74 (from 0.66).
from this time using TSIG on queries and updates
does not work anymore.
former i used:
$resolver = Net::DNS::Resolver->new(...);
$resolver->tsig( $keyname, $key );
# ($key as base64 representation)
or
$resolver->tsig( Net::DNS::RR->new( "$keyname TSIG $key" ) );
calling tsig now results in an expeption:
"zone file representation not defined for TSIG at /usr/lib/perl5/vendor_perl/5.18.2/i686-linux/Net/DNS/RR.pm line 683."
according to http://search.cpan.org/~nlnetlabs/Net-DNS-0.74/lib/Net/DNS/Resolver.pm#tsig
tsig() - Get or set the TSIG record used to automatically sign outgoing queries and updates.
my usage of tsig() should be correct.
using another way of pre-creating the tsig RR-Object with:
my $tsig = Net::DNS::RR->new( type => "TSIG", name => "KEYNAME", key => "KEY" );
$resolver->tsig($tsig);
results in "tsig verify failure (BADSIG)" Errors in BIND at server side.
using $tsig for update packets only:
my $update = Net::DNS::Update->new( ... );
$update->sign_tsig($tsig);
also does not work (BADSIG); the 'simpler' way
$update->sign_tsig($keyname, $key);
does work.
What is the correct way to use TSIG for both query and update packets with the resolver object in Net::DNS >= V0.74 ?
Perl Version is 5.18.2 .
what am i doing wrong ? - thanks a lot for your hints.
The TSIG functionality in Net::DNS had a complete rewrite around 0.74, and most releases since then have had bugfixes for some aspect of TSIG. I'd suggest that you try to forget how it used to work, re-read all the relevant documentation and then change your own code as needed.
Also, 0.74 is (in this context) pretty old. It would probably be a good idea to upgrade to something closer to current (which is 0.82 when I write this).

creating job with ssis step using tsql

I would like to create sql server job using stored procedure and I can't seem to get it right.
Integration Service Catologs -> SSIDB -> Cat1 ->Projects->999->Packages->999.dtsx
In step 1 properties of below script on Package tab "Server: and Package:" are empty, I need to populate these as well as set 32bit to true
Below is what I got, thanks in advance
EXECUTE msdb..sp_add_job #job_name = 'Job 1', #owner_login_name = SUSER_NAME(), #job_id = #JobId OUTPUT
EXECUTE msdb..sp_add_jobserver #job_id = #JobId, #server_name = ##SERVERNAME
EXECUTE msdb..sp_add_jobstep #job_id = #JobId, #step_name = 'Step1',#database_name = DB_NAME(), #on_success_action = 3 ,#subsystem = N'ssis'
, #command = N' "\SSISDB\Cat1\999\999.dtsx" #SERVER=N"#ServerName"'
EXECUTE msdb..sp_add_jobstep #job_id = #JobId, #step_name = 'Step2', #command = 'execute msdb..sp_delete_job #job_name="Job 1"'
EXECUTE msdb..sp_start_job #job_id = #JobId
if anyone else comes across similar situation, easiest way to figure out how to create a job pragmatically is to create it using UI (Server Agent -> New Job). create everything you want to see, save it, then right click at the job Script Job As -> Create To -> New query and sql server will export the job as a query so you can see what you need to do.
While we wait for clarification on the existing syntax, the two arguments to msdb..sp_add_jobstep that you need to be concerned with are the #subsystem and #command.
, #subsystem = N'SSIS'
, #command = N'/ISSERVER "\"\SSISDB\POC\SSISConfigMixAndMatch\Package.dtsx\"" /SERVER "\".\dev2014\"" /X86 /Par "\"$ServerOption::LOGGING_LEVEL(Int16)\"";1 /Par "\"$ServerOption::SYNCHRONIZED(Boolean)\"";True /CALLERINFO SQLAGENT /REPORTING E'
The GUI will build out these options happily but you can read the dtexec documentation and come to the same script.
/ISSERVER This specifies that we're using the fancy new execution engine built into the SSISDB
We pass in the package we want to execute to this option
/SERVER where will these packages be found
Specify the server name and optional instance
/X86 As the fine documentation notes, this option only works for invocation from SQL Agent but this is how you specify you need to use the 32 bit dtexec.exe
/Par Specify parameter values as needed
Indicates our standard, Basic, level of logging
The next instance of /Par specifies whether the caller should wait for the process to complete (synchronous versus asynchronous process). Yes, the job steps should wait for the process to complete.
/Reporting What information should be reported. This is odd because the useful information you used to get in an SQL Agent job report is no longer there. It will just say Consult the SSISDB reports for more information
E, report Errors only.

IDA "call offset"

I've dumped a dll from memory using LordPE, so far so good, but there are some functions IDA shows just like this:
call off_11CAE08
At memory address 11CAE08(.data section) we have 01058530(.text section) so I'd like IDA was able to show call sub_01058530, so, Is there any way or script that's able to change and fix all lines with this problem?
It's a relative call, you need to resolve that address. You can do this statically by looking at the library or you can do it dynamically by using a tool called Ablation, you can learn how to use it by listening to the authors talk at black hat. In order to do that you need to run the process/dll with ablation
Assuming you have 1-dref functions like this one, here is a script using sark:
from sark import *
from idc import *
from idaapi import *
from idautils import *
import struct
text_start =xxx
text_end= xxxx
data_start=xxx
data_end=xxx
for line in sark.lines(text_start, text_end):
for ref in line.xrefs_to:
if ref.type.is_call:
if data_start <= ref.to <= data_end:
addr = GetManyBytes(ref.to, 4)
addr, _ = struct.unpack("<I", addr)
MakeName(ref.to, "func_ptr_"+str(addr))
P.S. Im writing from my phone, so syntax may not be exact.

Perl generate random session id for high traffic

I am trying to generate a random id for sessions cookie for every user session in Perl. Of course I searched cpan and google and found many similar topics and same weakness. The most modules used are Digest::SHA and Data::UUID and the module Data::GUID which internally uses Data::UUID.
Here is the code I can summarize the most methods used in modules on cpan:
#!/usr/bin/perl
use v5.10;
use Digest::SHA;
use Data::UUID;
use Data::GUID;# uses Data::UUID internally, so no need for it
use Time::HiRes ();
for (1..10) {
#say generate_sha(1); # 1= 40 bytes, 256=64 bytes, 512=128 bytes, 512224, 512256
say generate_uuid();
#say generate_guid();
}
sub generate_sha {
my ($bits) = #_;
# SHA-1/224/256/384/512
return Digest::SHA -> new($bits) -> add($$, +{}, Time::HiRes::time(), rand(Time::HiRes::time()) ) -> hexdigest;
}
sub generate_uuid {
return Data::UUID->new->create_hex(); #create_str, create_b64
}
sub generate_guid {
# uses Data::UUID internally
return Data::GUID->guid;
}
Here is a sample output form Data::UUID module:
0x0217C34C6C0710149FE4C7FBB6FA663B
0x0218665F6C0710149FE4C7FBB6FA663B
0x0218781A6C0710149FE4C7FBB6FA663B
0x021889316C0710149FE4C7FBB6FA663B
0x021899E16C0710149FE4C7FBB6FA663B
0x0218AB2B6C0710149FE4C7FBB6FA663B
0x0218BB1D6C0710149FE4C7FBB6FA663B
0x0218CABD6C0710149FE4C7FBB6FA663B
0x0218DB786C0710149FE4C7FBB6FA663B
0x0218ED396C0710149FE4C7FBB6FA663B
The id's generated from these seems to be unique, but what I am concerning is about high traffic or concurrency, say what if a 1000 only not saying 1000,000 users connected at the same time either from the same process like running under FCGI (say each FCGI process serving only 10 users) or from separate processes like running under CGI mode.
In the SHA I used this random string:
($$, +{}, Time::HiRes::time(), rand(Time::HiRes::time())
it includes Anonymous hash reference address and the current time in microseconds with Time::HiRes::time. Is there any other ways to make random string.
I have read topics to add the Host name and IP address of the remote user but others say about proxies could be used.
I see Plack::Session::State module uses this simple code to generate id's:
Digest::SHA1::sha1_hex(rand() . $$ . {} . time)
So the question in short I want to generate a unique may be up to 64 bytes long session id guaranteed to work with high traffic.
You can safely use Data::UUID and you shouldn't be concerned about duplicates, you will not encounter them.
Also rand() will not return the same number when called subsequently even under assumption that it is called at the same moment of time. A pseudo random algorithm generates the next number based on its current state and the previously generated values. A true random generator is generally not used alone but in conjunction with a pseudo random number generator. In either case the likelihood of subsequently generated numbers to repeat between the nearest clock ticks in practical terms is negligible. In your example you may want to use rand(2**32).

Getting and setting priority value for a parent process and child process

I have a perl script which will create a child process. I need to get the priority(nice) value for these two process(parent and child)
I can get the pid of both parent and child process as below:
$parentPID = $$;
$childPID = fork();
How to get the priority values for these process in perl script?
Check getpriority() where first parameter for PID is PRIO_PROCESS (you can use BSD::Resource to import this constant or just use zero instead)
Reading current PID priority, and setting new one,
nice -7 perl -E'say getpriority(0,$$); setpriority(0,$$,9); say getpriority(0,$$)'
output
7
9
use the Forks::Super CPAN module. Example:
$pid = fork { os_priority => 10 }; # like nice(1) on Un*x
if you don't want to use a CPAN module, setpriority function sets the current priority for a process, a process group, or a user.