Leser: 25
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
use Win32::EventLog; use Win32::AuthenticateUser; #LOGIN Infos in ADM print "######LOGIN-INFOS######\n"; print 'Domain: '; chomp(my $domain = <STDIN>); print 'User: '; chomp(my $user = <STDIN>); my $password=&getpassword(); AuthenticateUser("$domain", "$user", "$password"); $myServer="\\\\XYCAA01"; # your servername here. my($date)=join("-", ((split(/\s+/, scalar(localtime)))[0,1,2,4])); my($dest); for my $eventLog ("Application", "System", "Security") { $handle=Win32::EventLog->new($eventLog, $myServer) or die "Can't open Application EventLog on $myServer\n"; $dest="C:\\WINDOWS\\Temp\\BackupEventLogs\\$eventLog\\$date.evt"; $handle->Backup($dest) or warn "Could not backup and clear the $eventLog EventLog on $myServer ($^E)\n"; $handle->Close; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
#!/usr/bin/perl use strict; use warnings; package Win32::LSA; use base qw/Win32::API::Interface/; __PACKAGE__->generate( "Advapi32.dll", "LogonUserA", "PPPIIP", "I", "logon_user" ); __PACKAGE__->generate( "Advapi32.dll", "ImpersonateLoggedOnUser", "I", "I", "impersonate_as" ); __PACKAGE__->generate( "Advapi32.dll", "RevertToSelf", "", "I", "revert" ); 1; use Win32 (); my $token = "\0" x 4; my $lsa = Win32::LSA->new; my $rc = $lsa->logon_user( $ENV{USER}, $ENV{DOMAIN}, $ENV{PASS}, 2, 0, $token); die Win32::FormatMessage( Win32::GetLastError ) unless $rc; print "Logon success\n"; $rc = $lsa->impersonate_as( unpack 'L', $token ); die Win32::FormatMessage( Win32::GetLastError ) unless $rc; print "Impersonate success.\n"; # hier dein code $rc = $lsa->revert; die Win32::FormatMessage( Win32::GetLastError ) unless $rc;
2010-05-20T07:32:07 esskarich bezog mich eher auf dein Win32::AuthenticateUser
das gibts nämlich dort nicht!!!
Guest werim Paket "Win32:LSA" wird mit "Win32::API::Interface" aus "Advapi32.dll" die Funktionen "LogonUserA", "ImpersonateLoggedOnUser" und "RevertToSelf" unter den Namen "logon_user", "impersonate_as" und "revert" in den Namespace importiert. "Win32::API::Interface" als Basisklasse für das Paket verwendet.
Dann erzeugt er ein neues Objekt aus dem Paket "Win32:LSA" und nutzt die gerade importierten Funktionen.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
package Win32::LSA; use base qw/Win32::API::Interface/; use strict; use warnings; __PACKAGE__->generate( "Advapi32.dll", "LogonUserA", "PPPIIP", "I", "logon_user" ); __PACKAGE__->generate( "Advapi32.dll", "ImpersonateLoggedOnUser", "P", "I", "impersonate_as" ); __PACKAGE__->generate( "Advapi32.dll", "RevertToSelf", "", "I", "revert" ); 1; use Win32 (); my $token = "\0" x 4; print "######LOGIN-INFOS######\n"; print 'Domain: '; chomp(my $domain = <STDIN>); print 'User: '; chomp(my $user = <STDIN>); my $password=&getpassword(); my $lsa = Win32::LSA->new; #my $rc = $lsa->logon_user( $ENV{USER}, $ENV{DOMAIN}, $ENV{PASS}, 5, 0, $token); my $rc = $lsa->logon_user( $user, $domain, $password, 5, 0, $token); die Win32::FormatMessage( Win32::GetLastError ) unless $rc; print "Logon success:\n"; $rc = $lsa->impersonate_as( $token ); die Win32::FormatMessage( Win32::GetLastError ) unless $rc; print "Impersonate success.\n"; # hier dein code $rc = $lsa->revert; die Win32::FormatMessage( Win32::GetLastError ) unless $rc; sub getpassword { #---------------------------------------------------- # getpassword # Passwort eingabe ohne das diese in der Comandozeile angezeigt wird #---------------------------------------------------- use Term::ReadKey; print 'Password: '; ReadMode 'noecho'; my $password = ReadLine; ReadMode 'normal'; chomp $password; return $password; }
QuoteAnmeldung fehlgeschlagen: Dem Benutzer wurde der angeforderte Anmeldetyp auf diesem Computer nicht erteilt.
QuoteLogon success:
Das Handle ist ung³ltig.
2010-05-20T10:20:41 esskarjetzt bin ich gespannt, ob das zusammen mit den events auch klappt.
unter c/c++ und winapi, würde man es zumindest so machen.
QuoteUndefined subroutine &Win32::LSA::getpassword called at new2.pl line 43, <STDIN> line 2.
Undefined subroutine &Win32::LSA::GetEvents called at new2.pl line 80, <STDIN> line 3.
2010-06-16T09:01:13 esskargetpassword und GetEvents ist ja nicht im WIN32::LSA package. zumindest hab ich sie da nicht reingepackt.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
sub BackupEvt { package Win32::LSA; use base qw/Win32::API::Interface/; use Win32::EventLog; __PACKAGE__->generate( "Advapi32.dll", "LogonUserA", "PPPIIP", "I", "logon_user" ); __PACKAGE__->generate( "Advapi32.dll", "ImpersonateLoggedOnUser", "I", "I", "impersonate_as" ); __PACKAGE__->generate( "Advapi32.dll", "RevertToSelf", "", "I", "revert" ); 1; use Win32 (); my $token = "\0" x 4; print "######LOGIN-INFOS######\n"; print 'Domain: '; chomp(my $domain = <STDIN>); print 'User: '; chomp(my $user = <STDIN>); my $password=&getpassword(); print "\nServer: "; chomp(my $server = <STDIN>); $server="Servername123"; my $lsa = Win32::LSA->new; my $rc = $lsa->logon_user( $user, $domain, $password, 2, 0, $token); die Win32::FormatMessage( Win32::GetLastError ) unless $rc; print "Logon success:\n"; $rc = $lsa->impersonate_as( unpack 'L', $token ); die Win32::FormatMessage( Win32::GetLastError ) unless $rc; print "Impersonate success.\n"; my $count = 0; while ($count < 2) { $myServer="\\\\$server"; # your servername here. my($date)=join("-", ((split(/\s+/, scalar(localtime)))[0,1,2,4])); my($dest); #Eventlogdateinamen my $evtDate = '29.3.2010'; for my $eventLog ("Application", "System") { $handle=Win32::EventLog->new($eventLog, $myServer) or die "Can't open $EventLog on $myServer\n"; my($name)=$server.'_'.$eventLog.'_'.$date; $dest="E:\\Share\\Logs\\events\\\\$name.evt" || die print "Could not open $dest from $server"; $handle->Backup($dest) or warn "Could not backup and clear the $eventLog EventLog on $myServer ($^E)\n"; ###EVT-Dateien auf dem Server auswerten### \&GetEvents($server,$dest,$evtDate,$eventLog); ########################### $handle->Close; } ###Daten lokal auf den PC speichern### #Netzlaufwerk verbinden #Ordner erstellen #Auswertung speichern ########################### &connect($domain, $user, $password, $server); &folder; ©($name); ########################### if ($server =~ /main/) { $server =~ tr/main/backup/;} else {last;} $count++ } $rc = $lsa->revert; die Win32::FormatMessage( Win32::GetLastError ) unless $rc; my @return = ($domain, $user, $password, $server, $name); return @return; }
1 2 3 4 5 6 7 8 9 10 11 12 13
package Win32::LSA; use base qw/Win32::API::Interface/; __PACKAGE__->generate( "Advapi32.dll", "LogonUserA", "PPPIIP", "I", "logon_user" ); __PACKAGE__->generate( "Advapi32.dll", "ImpersonateLoggedOnUser", "I", "I", "impersonate_as" ); __PACKAGE__->generate( "Advapi32.dll", "RevertToSelf", "", "I", "revert" ); 1; use strict; use warnings; use Win32 (); use Win32::EventLog;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#!/usr/bin/perl use strict; use warnings; use Win32 (); use Win32::EventLog; package Win32::LSA; use base qw/Win32::API::Interface/; __PACKAGE__->generate( "Advapi32.dll", "LogonUserA", "PPPIIP", "I", "logon_user" ); __PACKAGE__->generate( "Advapi32.dll", "ImpersonateLoggedOnUser", "I", "I", "impersonate_as" ); __PACKAGE__->generate( "Advapi32.dll", "RevertToSelf", "", "I", "revert" ); 1; package main; # ...
1 2 3 4 5 6
use Win32::OLE; use strict; use warnings; my $objnet=Win32::OLE->CreateObject("Wscript.Network"); $objnet->MapNetworkDrive("G:","\\\\Serverxy\\Ordnerxy\\");
system("net use B: \\\\$SERVER\\$FOLDER");
1 2 3
$evt = Win32::EventLog->new($path) || die "Could not open $log log on $server: $!\n"; $evt->GetNumber($total) || die "Can't get the higest number of EventLog records: $!\n"; $evt->GetOldest($oldest) || die "Can't get number of oldest EventLog record: $!\n";
Quote$!
If used numerically, yields the current value of the C "errno" variable, or in other words, if
a system or library call fails, it sets this variable. This means that the value of $! is
meaningful only immediately after a failure:
2010-06-16T10:12:16 LukeStrikerAhh okay, also Fehler vorhanden nur nicht in $!...
die Win32::FormatMessage( Win32::GetLastError )