Date post: | 29-Nov-2014 |
Category: |
Technology |
Upload: | adesso-ag |
View: | 127 times |
Download: | 0 times |
Short run
► Überlick zu SNMP (ganz kurz)
► Konfiguration und Anwendung von Net-SNMP
► SNMPv3 mit Net-SNMP
► TLS/DTLS mit Net-SNMP
► SNMP von Java aus nutzen
09.05.2014 SNMP Applied3
Grundlegendes zu SNMP
Historisches zu SNMP
► Simple Network Management Protocol
> Verwendet UDP, Ports 161 und 162
> TCP alternativ möglich
► Historie
> 1988: Version 1, Ursprüngliche Spezifikation in RFC 1155-1157
> 1992: Secure SNMP, RFC1351-1353,nie offiziell eingeführt
> 1993: Party-based SNMP (SNMPv2p) RFC 1441, 1445-1447,führte getbulk ein, erhöhte Sicherheit, heute nicht mehr im Einsatz
> 1996: User-based SNMP (SNMPv2u) RFC 1909-1910,heute nicht mehr im Einsatz
> 1996: Community-based SNMP (SNMPv2c) RFC 1901, 1905-1906,Erweiterung von Version 1 um Features aus SNMPv2p
> 2002: Version 3 (SNMPv3), RFC 3410-3418,Fokus auf Sicherheit
09.05.2014 SNMP Applied5
Anwendungen von SNMP
► Kontinuierliches Monitoring (Polling)
> Uptime, Load
> Netzwerkverkehr
> Speicherverbrauch (RAM, Festplatten)
> Hardware-Zustand (S.M.A.R.T., Lüfterdrehzahl)
► Information über Ereignisse (SNMP-Traps)
> Fehlersituationen
> Zustandswechsel
09.05.2014 SNMP Applied6
SNMP Begriffswelt
► Agent – SNMP-Daemon, der Informationen via UDP 161 bereitstellt oder Traps via UDP 162 versendet
► Manager – SNMP-Client, der Informationen via UDP 161 einsammelt
► Trap – SNMP-Nachricht, über UDP 162 versendet
► MIB – Management Information Base> Dateien mit strukturiertem Text nach ASN.1
> Beschreiben Monitoring-Objekte
> Übersetzen OIDs in Namen und interpretieren der entsprechenden Werte
► OID – Object Identifier
> Identifikatoren in durch ASN.1 definiertem Namensraum
► community – in SNMPv1 und SNMPv2c zur Anmeldung am Agent verwendet
09.05.2014 SNMP Applied7
Der MIB-Tree
09.05.2014 SNMP Applied8
Die Position im MIB-Tree liefert den OID eines Objektes.
Die Private Enterprise Number der adessoAG ist 36467.
SNMP-Objekte der adesso AG beginnen immer mit1.3.6.1.4.1.36467.
root
ccitt(0) iso(1) joint-iso-ccitt(2)
org(3)
dod(6)
internet(1)
directory(1) mgmt(2) experimental(3) private(4)
enterprises(1)
adesso(36467)
mib-2(1)
system(1)
interfaces(2)
ip(4)
snmp(11)
host(25)
OID: Object Identifier
► OIDs sind eindeutige Identifikatoren innerhalb eines Agenten bzw. eines Gerätes
► OIDs bilden die Navigation durch den MIB-Tree
► Hersteller-spezifische OIDs immer unterhalb von 1.3.6.1.4.1
► Mapping auf Domains> 1.3.6.1.4.1.36467 –
adesso.enterprises.private.internet.dod.iso.org.
► Unterhalb der OID ist jeder Hersteller frei in seinen Definitionen
► Zuweisung der Enterprise-Identifkation erfolgt durch die IANA: http://www.iana.org/assignments/enterprise-numbers
09.05.2014 SNMP Applied9
Net-SNMP
Net-SNMP
► OpenSource SNMP Implementierung (CMU, BSD-Like)
► Läuft auf fast allen Unix- und Linux-Systemen
► Unterstützt SNMP Version 1, SNMPv2c, SNMPv3 via IPv4 und IPv6
► Kommandozeilenapplikationen zu
> Abfrage von SNMP-Agents (snmpget, snmpwalk, …)
> Ändern von Konfigurationen via SNMP (snmpset)
> Übersetzen von OIDs (snmptranslate)
► Daemon zum Empfangen von SNMP Traps (snmptrapd)
► Daemon als SNMP Agent (snmpd)
► C- und Perl-APIs
► Zu finden hier: http://www.net-snmp.org/
09.05.2014 SNMP Applied11
Net-SNMP snmpd konfigurieren
► Minimale Konfiguration definiert Standort, Kontakt und erlaubt Auslesen
09.05.2014 SNMP Applied12
# /etc/snmp/snmpd.confsyslocation Server Roomsyscontact Sysadmin (root@localhost)
# listen on all interfacesagentAddress udp:161# allow localhost read-only access via community pub licrocommunity public 127.0.0.1# allow whole network read-only access via communit y publicrocommunity public 192.168.79.0/24
► Abfrage des snmpd erfolgt via snmpwalk
~$ snmpwalk -c public -v1 snmp.devSNMPv2-MIB::sysDescr.0 = STRING: Linux linux-dwoa 3. 1.10-1.16-default #1 SMP Wed Jun 27 05:21:40 UTC 2012 (d016078) x86_64SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netS nmpAgentOIDs.10DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (63 5449) 1:45:54.49SNMPv2-MIB::sysContact.0 = STRING: Sysadmin (root@lo calhost)SNMPv2-MIB::sysName.0 = STRING: linux-dwoaSNMPv2-MIB::sysLocation.0 = STRING: Server Room...
09.05.2014 SNMP Applied13
Das Problem:Das ist alles total unsicher!
Schwächen von SNMPv1 und SNMPv2c
► Autorisierung erfolgt über die IP-Adresse
► Authentifizierung erfolgt über Community
► Einschränkungen der Community gelten jeweils pro IP-Adresse
► Übertragung erfolgt unverschlüsselt
► Standard-Protokoll UDP sicher Datenübertragung nicht ab
09.05.2014 SNMP Applied14
Net-SNMP für SNMPv3 konfigurieren I
► Benutzer anlegen
09.05.2014 SNMP Applied15
~$ /etc/init.d/snmpd stop~$ net-snmp-config --create-snmpv3-user -a "secretpw " snmpUser~$ /etc/init.d/snmpd start
► Minimale Konfiguration für SNMPv3# /etc/snmp/snmpd.confsyslocation Server Roomsyscontact Sysadmin (root@localhost)
# listen on all interfacesagentAddress udp:161
# /usr/share/snmp/snmpd.conf !! :-(# Via `net-snmp-config` erzeugt
rwuser snmpUser
# /var/lib/net-snmp/snmpd.conf (openSUSE)# /var/lib/snmp/snmpd.conf (Debian)
################################################### ####################### STOP STOP STOP STOP STOP STOP STOP STOP STOP## **** DO NOT EDIT THIS FILE ****## STOP STOP STOP STOP STOP STOP STOP STOP STOP################################################### ######################...
Net-SNMP für SNMPv3 konfigurieren II
► Minimale Konfiguration für SNMPv3
09.05.2014 SNMP Applied16
► Abfrage testen (unverschlüsselt und verschlüsselt)~$ snmpget -v 3 -u snmpUser -l authNoPriv -a MD5 -A se cretpw \
snmp.dev sysUpTime.0DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (88 05) 0:01:28.05
~$ snmpget -v 3 -u snmpUser -l authPriv -a MD5 -A secr etpw \-x DES -X secretpw snmp.dev sysUpTime.0
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (98 35) 0:01:38.35
Benutzer hinzufügen I
► Neue Benutzer benötigen einen Template-User
► Benutzer hinzufügen mit snmpusm
► Danach unbedingt das Passwort ändern
09.05.2014 SNMP Applied17
~$ snmpusm -v 3 -u gbeine -l authPriv -a MD5 -A secret pw \-x DES -X secretpw snmp.dev passwd secretpw strenggehei m
SNMPv3 Key(s) successfully changed.
~$ snmpget -v 3 -u gbeine -l authNoPriv -a MD5 -A stre nggeheim \snmp.dev sysUpTime.0
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (58 71) 0:00:58.71
~$ snmpusm -v 3 -u snmpUser -l authNoPriv -a MD5 -A se cretpw \snmp.dev create gbeine snmpUser
User successfully created.
~$ snmpget -v 3 -u gbeine -l authNoPriv -a MD5 -A secr etpw \snmp.dev sysUpTime.0
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (11 303) 0:01:53.03
► Achtung: Neue Benutzer und Passwortänderungen sind zwar sofort verfügbar, aber noch nicht persistiert!
# /etc/snmp/snmpd.confsyslocation Server Roomsyscontact Sysadmin (root@localhost)
# listen on all interfacesagentAddress udp:161
# new userrwuser gbeine
Benutzer hinzufügen II
► Benutzer in Konfiguration eintragen und SNMP neu starten
09.05.2014 SNMP Applied18
► Abfrage testen (unverschlüsselt und verschlüsselt)
# /var/lib/net-snmp/snmpd.conf (openSUSE)# /var/lib/snmp/snmpd.conf (Debian)# ...usmUser 1 3 0x80001f88804162a72b6c8c205300000000 "gb eine" "gbeine" NULL \
.1.3.6.1.6.3.10.1.1.2 0x0a32bdbfcc9830326f7a6353a4f ef86e \
.1.3.6.1.6.3.10.1.2.2 0x0a32bdb
http://www.net-snmp.org/docs/man/snmpd.conf.html: „It is recommended you use the net-snmp-config command to do this“
Luxus auf Client-Seite
09.05.2014 SNMP Applied19
► Aufruf mit SNMPv3 wird recht kompliziert~$ snmpget -v 3 -u snmpUser -l authPriv -a MD5 -A secr etpw \
-x DES -X secretpw snmp.dev sysUpTime.0DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (98 35) 0:01:38.35
► Client Konfiguration für snmpget, snmpwalk, snmpset, ...
# ~/.snmp/snmp.conf
defSecurityName gbeinedefSecurityLevel authPrivdefAuthType MD5defAuthPassphrase strenggeheimdefPrivType DESdefPrivPassphrase strenggeheimdefVersion 3
► Danach schon deutlich einfacher~$ snmpget snmp.dev sysUpTime.0DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (58 71) 0:00:58.71
Sicherheit erhöhen
09.05.2014 SNMP Applied20
► Verschlüsselung auf Seite des Servers erzwingen:# /etc/snmp/snmpd.conf# ...rwuser gbeine priv
► Danach ist -l authNoPriv auf Client-Seite nicht mehr möglich :-)
► Passwort durch Diffie-Hellman-Keys ersetzen:~$ snmpusm snmp.dev changekey gbeinenew auth key: 0x0404e48a606a7dc5ce0fe23d83257f91new priv key: 0x092d15bea5298a286911692b28a9fc64SNMPv3 Key(s) successfully changed.
► Client Konfiguration anpassen:# ~/.snmp/snmp.conf
defSecurityName gbeinedefSecurityLevel authPrivdefVersion 3defAuthLocalizedKey 0x0404e48a606a7dc5ce0fe23d83257f 91defPrivLocalizedKey 0x092d15bea5298a286911692b28a9fc 64
Zugriffsbeschränkungen
09.05.2014 SNMP Applied21
► Zugriff von Usern oder Communities auf OIDs beschränken# /etc/snmp/snmpd.conf# ...rwuser gbeine priv .1.3.6.1.2.1.1# alternativ etwas besser lesbar# rwuser gbeine priv system
► Lese-/Schreibzugriff pro Benutzer festgelegt
► Zugriff für jeden Benutzer auf Subtree der OID eingeschränkt
► Lösung dazu ist VACM (SNMPv3 View Based Access Control)
SNMPv3 VACM
09.05.2014 SNMP Applied22
► Zugriff von Usern oder Communities auf OIDs beschränken# /etc/snmp/snmpd.conf# ...rwuser gbeine priv -V basic
view basic included systemview basic included interfaces
► View können OID-Subtree ein- und ausschließen
► Mehrere Einträge mit gleichem Namen werden zusammengefasst
► Weitere Einschränkungen möglich mit com2sec, group, access
Verbesserungen gegenüber SNMPv1 und SNMPv2c
► Authentifizierung erfolgt über Benutzer-Account
► Übertragung kann mit persönlichen Credentials verschlüsselt werden
► Verschlüsselung durch Server erzwungen
► Credentials durch sichere Diffie-Hellman-Keys ausgetauscht
► Beschränkung der Benutzer auf Teilbäume des MIB-Tree
► Festlegung von Lese-/Schreibrechten auf OID-Ebene
09.05.2014 SNMP Applied23
Net-SNMP mit DTLS/TLS
Net-SNMP mit DTLS/TLS
► Net-SNMP beherrscht sowohl UDP als auch TCP
► Dank OpenSSL kann TLS und Datagram TLS (DTLS) verwendet werden
► Net-SNMP bringt eigene Tools zur Verwaltung von Zertifikaten mit
► Verfügbar ab Net-SNMP 5.6
► Debian liefert Net-SNMP 5.4 (zu alt)
► openSUSE liefert Net-SNMP 5.7, leider ohne DTLS/TLS Support
► Rebuild notwendig mit folgenden Optionen:
09.05.2014 SNMP Applied25
~$ ./configure .. \--with-security-modules=tsm \--with-transports=TLSTCP,DTLSUDP
Zertifikate erstellen
09.05.2014 SNMP Applied26
► Certificate Authority zum Signieren von Zertifikaten~$ net-snmp-cert genca -I -n ca.snmp.devCA Generated:
ca-certs/ca.snmp.dev.crtprivate/ca.snmp.dev.key
► Server-Zertifikat erstellen (wichtig ist -t snmpd )~$ net-snmp-cert gencsr -I -t snmpd -n snmp.devCertificate Signing Request Generated:
newcerts/snmpd.csrprivate/snmpd.key
► Client-Zertifikat erstellen (wichtig ist -n gbeine )~$ net-snmp-cert gencsr -I -t manager -n gbeineCertificate Signing Request Generated:
newcerts/manager.csrprivate/manager.key
► Zertifikate signieren~$ net-snmp-cert signcsr -I --with-ca ca.snmp.dev --csr snmpd~$ net-snmp-cert signcsr -I --with-ca ca.snmp.dev --c sr manager
Konfiguration des Servers für DTLS
► Fingerprint der Zertifikate auslesen
09.05.2014 SNMP Applied27
~$ net-snmp-cert showcerts --fingerprint /etc/snmp/tls:
certs/manager.crt:SHA1 Fingerprint=50:43:06:3E:5A:94:2C:51:3D:8B:32:81:68: B4:D3:BB:97:B2:9C:C4
certs/snmpd.crt:SHA1 Fingerprint=78:11:C4:BE:D2:79:D6:00:4C:E0:0E:BC:0A: 95:3B:92:1E:D3:26:41
► Konfiguration anpassen
# /etc/snmp/snmpd.conf# ...
# listen on all interfacesagentAddress udp:161, dtlsudp:10161
# certificate for user gbeinecertSecName 10 \50:43:06:3E:5A:94:2C:51:3D:8B:32:81:68:B4:D3:BB:97: B2:9C:C4 --cn
Konfiguration auf Client-Seite
09.05.2014 SNMP Applied28
► SNMPv3 über DTLS (ohne Client-Konfiguration)
~$ snmpget -v 3 --defSecurityModel=tsm -u gbeine -l au thPriv \-T our_identity=50:43:06:3E:5A:94:2C:51:3D:8B:32:81 :68:B4:D3:BB:97:B2:9C:C4 \-T their_identity=78:11:C4:BE:D2:79:D6:00:4C:E0:0E: BC:0A:95:3B:92:1E:D3:26:41 \dtlsudp:localhost:10161 sysUpTime.0DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (12 0) 0:00:01.20
► Client Konfiguration für snmpget, snmpwalk, snmpset, ...# ~/.snmp/snmp.conf
defSecurityLevel authPrivdefVersion 3defSecurityModel tsmlocalCert 50:43:06:3E:5A:94:2C:51:3D:8B:32:81:68:B4: D3:BB:97:B2:9C:C4peerCert 78:11:C4:BE:D2:79:D6:00:4C:E0:0E:BC:0A:95:3 B:92:1E:D3:26:41
► SNMPv3 über DTLS (mit Client-Konfiguration)~$ snmpget dtlsudp:localhost:10161 sysUpTime.0DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (12 0) 0:00:01.20
SNMP-Zugriff mit Java
Einfaches SNMP v1 get I
public class SimpleGet {
private static String hostName = "snmp.dev" ;private static String port = "161" ;// OID via snmptranslate -On -IR sysUpTime.0private static String oid = ".1.3.6.1.2.1.1.3.0" ;private static int snmpVersion = SnmpConstants. version1;private static String community = "public" ;
public static void main(String[] args) throws Exception{
// Create Target Address objectCommunityTarget target = new CommunityTarget();target.setAddress( new UdpAddress( hostName + "/" + port));target.setVersion( snmpVersion);target.setCommunity( new OctetString( community));
// Create the PDU objectPDU pdu = new PDU();pdu.add( new VariableBinding( new OID( oid)));pdu.setType(PDU. GET);
// Create TransportMapping and send SNMP getTransportMapping<UdpAddress>transport = new DefaultUdpTransportMapping();transport.listen();Snmp snmp = new Snmp(transport);ResponseEvent response = snmp.get(pdu, target);snmp.close();
...
09.05.2014 SNMP Applied30
Einfaches SNMP v1 get II
09.05.2014 SNMP Applied31
...// Process Agent Responseif (response != null) {
PDU responsePDU = response.getResponse();
if (responsePDU != null) {int errorStatus = responsePDU.getErrorStatus();int errorIndex = responsePDU.getErrorIndex();final String errorStatusText = responsePDU.getErrorStatusT ext();
if (errorStatus == PDU. noError) {System. out.println( "Snmp Get Response = " + responsePDU.getVariableBindings());
} else {System. out.println( "Error: Request Failed" );System. out.println( "Error Status = " + errorStatus);System. out.println( "Error Index = " + errorIndex);System. out.println( "Error Status Text = " + errorStatusText);
}} else {
System. out.println( "Error: Response PDU is null" );}
} else {System. out.println( "Error: Agent Timeout... " );
}}}
SNMP v3 get mit Authentifizierung und Verschlüsselung I
09.05.2014 SNMP Applied32
public class V3Get {
private static String hostName = "snmp.dev" ;private static String port = "161" ;private static int snmpVersion = SnmpConstants. version3;private static int securityLevel = SecurityLevel. AUTH_PRIV;private static OID securityAuth = AuthMD5. ID;private static OID securityPriv = PrivDES. ID;private static String username = "gbeine" ;private static String password = "strenggeheim" ;
// OID via snmptranslate -On -IR sysUpTime.0private static String oid = ".1.3.6.1.2.1.1.3.0" ;
public static void main(String[] args) throws Exception{
final OctetString secUserName = new OctetString( username);final OctetString secPassword = new OctetString( password);
// Create Target Address objectUserTarget target = new UserTarget();target.setAddress( new UdpAddress( hostName + "/" + port));target.setVersion( snmpVersion);target.setSecurityLevel( securityLevel);target.setSecurityName(secUserName);
// Create the PDU objectScopedPDU pdu = new ScopedPDU();pdu.add( new VariableBinding( new OID( oid)));pdu.setType(PDU. GET);
...
SNMP v3 get mit Authentifizierung und Verschlüsselung II
09.05.2014 SNMP Applied33
...// Create TransportMappingTransportMapping<UdpAddress>transport = new DefaultUdpTransportMapping();transport.listen();Snmp snmp = new Snmp(transport);
// Initialize security modelUSM usm = new USM(SecurityProtocols. getInstance(),
new OctetString(MPv3. createLocalEngineID()), 0);SecurityModels. getInstance().addSecurityModel(usm);
// User authentication data (priv is forced)UsmUser user = new UsmUser(secUserName, securityAuth,
secPassword, securityPriv, secPassword);snmp.getUSM().addUser(secUserName, user);
// Send SNMP getResponseEvent response = snmp.get(pdu, target);snmp.close();
...
SNMP v3 get mit Authentifizierung und Verschlüsselung III
09.05.2014 SNMP Applied34
...// Process Agent Responseif (response != null) {
PDU responsePDU = response.getResponse();
if (responsePDU != null) {int errorStatus = responsePDU.getErrorStatus();int errorIndex = responsePDU.getErrorIndex();final String errorStatusText = responsePDU.getErrorStatusT ext();
if (errorStatus == PDU. noError) {System. out.println( "Snmp Get Response = " + responsePDU.getVariableBindings());
} else {System. out.println( "Error: Request Failed" );System. out.println( "Error Status = " + errorStatus);System. out.println( "Error Index = " + errorIndex);System. out.println( "Error Status Text = " + errorStatusText);
}} else {
System. out.println( "Error: Response PDU is null" );}
} else {System. out.println( "Error: Agent Timeout... " );
}}}
Weiterführendes
Literaturempfehlungen
► Net-SNMP: http://www.net-snmp.org/docs/
► SNMP4J: http://www.snmp4j.org/
► Evan McGinnis, David Perkins: Understanding SNMP Mibshttp://www.amazon.de/Understanding-SNMP-Mibs-Evan-McGinnis/dp/0134377087/
► Douglas R. Mauro, Kevin J. Schmidt: Essential SNMPhttp://www.amazon.de/Essential-SNMP-System-Network-Administrators/dp/0596008406/
09.05.2014 SNMP Applied36