|
@@ -1,24 +1,14 @@
|
|
package de.tudarmstadt.informatik.hostage.protocol;
|
|
package de.tudarmstadt.informatik.hostage.protocol;
|
|
|
|
|
|
import android.content.SharedPreferences;
|
|
import android.content.SharedPreferences;
|
|
-import android.preference.PreferenceManager;
|
|
|
|
|
|
|
|
-import java.io.File;
|
|
|
|
-import java.io.IOException;
|
|
|
|
-import java.util.List;
|
|
|
|
-
|
|
|
|
-import de.tudarmstadt.informatik.hostage.Hostage;
|
|
|
|
-import de.tudarmstadt.informatik.hostage.Listener;
|
|
|
|
-import de.tudarmstadt.informatik.hostage.R;
|
|
|
|
-import de.tudarmstadt.informatik.hostage.wrapper.Packet;
|
|
|
|
-
|
|
|
|
-import org.alfresco.jlan.server.auth.spnego.OID;
|
|
|
|
import org.snmp4j.TransportMapping;
|
|
import org.snmp4j.TransportMapping;
|
|
import org.snmp4j.agent.BaseAgent;
|
|
import org.snmp4j.agent.BaseAgent;
|
|
import org.snmp4j.agent.CommandProcessor;
|
|
import org.snmp4j.agent.CommandProcessor;
|
|
import org.snmp4j.agent.DuplicateRegistrationException;
|
|
import org.snmp4j.agent.DuplicateRegistrationException;
|
|
import org.snmp4j.agent.MOGroup;
|
|
import org.snmp4j.agent.MOGroup;
|
|
import org.snmp4j.agent.ManagedObject;
|
|
import org.snmp4j.agent.ManagedObject;
|
|
|
|
+import org.snmp4j.agent.mo.MOAccessImpl;
|
|
import org.snmp4j.agent.mo.MOTableRow;
|
|
import org.snmp4j.agent.mo.MOTableRow;
|
|
import org.snmp4j.agent.mo.snmp.RowStatus;
|
|
import org.snmp4j.agent.mo.snmp.RowStatus;
|
|
import org.snmp4j.agent.mo.snmp.SnmpCommunityMIB;
|
|
import org.snmp4j.agent.mo.snmp.SnmpCommunityMIB;
|
|
@@ -32,16 +22,30 @@ import org.snmp4j.security.SecurityLevel;
|
|
import org.snmp4j.security.SecurityModel;
|
|
import org.snmp4j.security.SecurityModel;
|
|
import org.snmp4j.security.USM;
|
|
import org.snmp4j.security.USM;
|
|
import org.snmp4j.smi.Address;
|
|
import org.snmp4j.smi.Address;
|
|
|
|
+import org.snmp4j.smi.Gauge32;
|
|
import org.snmp4j.smi.GenericAddress;
|
|
import org.snmp4j.smi.GenericAddress;
|
|
import org.snmp4j.smi.Integer32;
|
|
import org.snmp4j.smi.Integer32;
|
|
|
|
+import org.snmp4j.smi.OID;
|
|
import org.snmp4j.smi.OctetString;
|
|
import org.snmp4j.smi.OctetString;
|
|
|
|
+import org.snmp4j.smi.SMIConstants;
|
|
import org.snmp4j.smi.Variable;
|
|
import org.snmp4j.smi.Variable;
|
|
import org.snmp4j.transport.TransportMappings;
|
|
import org.snmp4j.transport.TransportMappings;
|
|
|
|
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+import de.tudarmstadt.informatik.hostage.Listener;
|
|
|
|
+import de.tudarmstadt.informatik.hostage.protocol.SNMPUtils.MOTableBuilder;
|
|
|
|
+import de.tudarmstadt.informatik.hostage.wrapper.Packet;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Created by root on 06.07.15.
|
|
* Created by root on 06.07.15.
|
|
*/
|
|
*/
|
|
public class SNMP extends BaseAgent implements Protocol {
|
|
public class SNMP extends BaseAgent implements Protocol {
|
|
|
|
+
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public int getPort() {
|
|
public int getPort() {
|
|
return 161;
|
|
return 161;
|
|
@@ -59,12 +63,22 @@ public class SNMP extends BaseAgent implements Protocol {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public List<Packet> processMessage(Packet requestPacket) {
|
|
public List<Packet> processMessage(Packet requestPacket) {
|
|
- return null;
|
|
|
|
|
|
+ List<Packet> responsePackets = new ArrayList<Packet>();
|
|
|
|
+
|
|
|
|
+ responsePackets.add(requestPacket);
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ setUp();
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return responsePackets;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public TALK_FIRST whoTalksFirst() {
|
|
public TALK_FIRST whoTalksFirst() {
|
|
- return null;
|
|
|
|
|
|
+ return TALK_FIRST.CLIENT;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -73,42 +87,67 @@ public class SNMP extends BaseAgent implements Protocol {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- private String address;
|
|
|
|
|
|
|
|
- private String externalIP;
|
|
|
|
|
|
+ private String address;
|
|
|
|
|
|
- SharedPreferences pref1;
|
|
|
|
|
|
+ private String externalIP;
|
|
|
|
|
|
- private Listener sListener;
|
|
|
|
|
|
+ SharedPreferences pref1;
|
|
|
|
+
|
|
|
|
+ private Listener sListener;
|
|
|
|
+
|
|
|
|
+ public SNMP(String address) throws IOException {
|
|
|
|
+
|
|
|
|
+ super(new File("conf.agent"), new File("bootCounter.agent"),
|
|
|
|
+ new CommandProcessor(
|
|
|
|
+ new OctetString(MPv3.createLocalEngineID())));
|
|
|
|
+ this.address = address;
|
|
|
|
+ }
|
|
|
|
|
|
- public SNMP(String address) throws IOException {
|
|
|
|
|
|
|
|
- super(new File("conf.agent"), new File("bootCounter.agent"),
|
|
|
|
- new CommandProcessor(
|
|
|
|
- new OctetString(MPv3.createLocalEngineID())));
|
|
|
|
- this.address = address;
|
|
|
|
- }
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- protected void registerManagedObjects() {
|
|
|
|
|
|
+ protected void addCommunities(SnmpCommunityMIB snmpCommunityMIB) {
|
|
|
|
|
|
|
|
+ Variable[] com2sec = new Variable[]{
|
|
|
|
+
|
|
|
|
+ new OctetString("public"),
|
|
|
|
+
|
|
|
|
+ new OctetString("cpublic"), // security name
|
|
|
|
+
|
|
|
|
+ getAgent().getContextEngineID(), // local engine ID
|
|
|
|
+
|
|
|
|
+ new OctetString("public"), // default context name
|
|
|
|
+
|
|
|
|
+ new OctetString(), // transport tag
|
|
|
|
+
|
|
|
|
+ new Integer32(StorageType.nonVolatile), // storage type
|
|
|
|
+
|
|
|
|
+ new Integer32(RowStatus.active) // row status
|
|
|
|
+
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ MOTableRow row = snmpCommunityMIB.getSnmpCommunityEntry().createRow(
|
|
|
|
+
|
|
|
|
+ new OctetString("public2public").toSubIndex(true), com2sec);
|
|
|
|
+
|
|
|
|
+ snmpCommunityMIB.getSnmpCommunityEntry().addRow((SnmpCommunityMIB.SnmpCommunityEntryRow) row);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
- protected void unregisterManagedObjects() {
|
|
|
|
|
|
+ protected void addNotificationTargets(SnmpTargetMIB snmpTargetMIB, SnmpNotificationMIB snmpNotificationMIB) {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
protected void addUsmUser(USM usm) {
|
|
protected void addUsmUser(USM usm) {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- @Override
|
|
|
|
- protected void addNotificationTargets(SnmpTargetMIB snmpTargetMIB, SnmpNotificationMIB snmpNotificationMIB) {
|
|
|
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
protected void addViews(VacmMIB vacmMIB) {
|
|
protected void addViews(VacmMIB vacmMIB) {
|
|
@@ -124,95 +163,123 @@ public class SNMP extends BaseAgent implements Protocol {
|
|
new OctetString(), VacmMIB.vacmViewIncluded, StorageType.nonVolatile);
|
|
new OctetString(), VacmMIB.vacmViewIncluded, StorageType.nonVolatile);
|
|
}
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
|
- protected void addCommunities(SnmpCommunityMIB snmpCommunityMIB) {
|
|
|
|
|
|
|
|
- Variable[] com2sec = new Variable[]{new OctetString("public"),
|
|
|
|
|
|
|
|
- new OctetString("cpublic"), // security name
|
|
|
|
|
|
|
|
- getAgent().getContextEngineID(), // local engine ID
|
|
|
|
-
|
|
|
|
- new OctetString("public"), // default context name
|
|
|
|
|
|
|
|
- new OctetString(), // transport tag
|
|
|
|
|
|
+ @Override
|
|
|
|
+ protected void registerManagedObjects() {
|
|
|
|
|
|
- new Integer32(StorageType.nonVolatile), // storage type
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- new Integer32(RowStatus.active) // row status
|
|
|
|
|
|
+ @Override
|
|
|
|
+ protected void unregisterManagedObjects() {
|
|
|
|
|
|
- };
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- MOTableRow row = snmpCommunityMIB.getSnmpCommunityEntry().createRow(
|
|
|
|
|
|
|
|
- new OctetString("public2public").toSubIndex(true), com2sec);
|
|
|
|
|
|
|
|
- snmpCommunityMIB.getSnmpCommunityEntry().addRow((SnmpCommunityMIB.SnmpCommunityEntryRow) row);
|
|
|
|
|
|
+ public SNMP() {
|
|
|
|
+ super("");
|
|
}
|
|
}
|
|
|
|
|
|
- public void start() {
|
|
|
|
|
|
|
|
- try {
|
|
|
|
- init();
|
|
|
|
- } catch (IOException e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- }
|
|
|
|
- // This method reads some old config from a file and causes
|
|
|
|
- // unexpected behavior.
|
|
|
|
- // loadConfig(ImportModes.REPLACE_CREATE);
|
|
|
|
- addShutdownHook();
|
|
|
|
- getServer().addContext(new OctetString("public"));
|
|
|
|
|
|
|
|
|
|
|
|
- finishInit();
|
|
|
|
- run();
|
|
|
|
- sendColdStartNotification();
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
+ public void start() throws IOException{
|
|
|
|
|
|
- protected void initTransportMappings() {
|
|
|
|
- transportMappings = new TransportMapping[1];
|
|
|
|
- Address addr = GenericAddress.parse(address);
|
|
|
|
|
|
|
|
- TransportMapping tm = TransportMappings.getInstance()
|
|
|
|
- .createTransportMapping(addr);
|
|
|
|
- transportMappings[0] = tm;
|
|
|
|
- }
|
|
|
|
|
|
+ init();
|
|
|
|
+ try {
|
|
|
|
+ setUp();
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
- public void registerManagedObject(ManagedObject mo) {
|
|
|
|
- try {
|
|
|
|
- server.register(mo, null);
|
|
|
|
- } catch (DuplicateRegistrationException ex) {
|
|
|
|
|
|
+ // This method reads some old config from a file and causes
|
|
|
|
+ // unexpected behavior.
|
|
|
|
+ // loadConfig(ImportModes.REPLACE_CREATE);
|
|
|
|
+ addShutdownHook();
|
|
|
|
+ getServer().addContext(new OctetString("public"));
|
|
|
|
+ finishInit();
|
|
|
|
+ run();
|
|
|
|
+ sendColdStartNotification();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ protected void initTransportMappings() throws IOException {
|
|
|
|
+ transportMappings = new TransportMapping[1];
|
|
|
|
+ Address addr = GenericAddress.parse(address);
|
|
|
|
|
|
- throw new RuntimeException(ex);
|
|
|
|
|
|
+ TransportMapping tm = TransportMappings.getInstance()
|
|
|
|
+ .createTransportMapping(addr);
|
|
|
|
+ transportMappings[0] = tm;
|
|
}
|
|
}
|
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
+ public void registerManagedObject(ManagedObject mo) {
|
|
|
|
+ try {
|
|
|
|
+ server.register(mo, null);
|
|
|
|
+ } catch (DuplicateRegistrationException ex) {
|
|
|
|
+
|
|
|
|
+ throw new RuntimeException(ex);
|
|
|
|
+ }
|
|
|
|
|
|
- public void unregisterManagedObject(MOGroup moGroup) {
|
|
|
|
- moGroup.unregisterMOs(server, getContext(moGroup));
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- //Listner for SNMP
|
|
|
|
- public Listener getListener() {
|
|
|
|
- return sListener;
|
|
|
|
|
|
|
|
|
|
+ public void unregisterManagedObject(MOGroup moGroup) {
|
|
|
|
+ moGroup.unregisterMOs(server, getContext(moGroup));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- public void initialize(Listener sListener) {
|
|
|
|
|
|
|
|
- this.sListener = sListener;
|
|
|
|
-
|
|
|
|
- // Hostage service = sListener.getService();
|
|
|
|
- // pref1 = PreferenceManager.getDefaultSharedPreferences(service);
|
|
|
|
- // agent = new SNMP();
|
|
|
|
- // externalIP = connInfo.getString(service.getString(R.string.connection_info_external_ip), null);
|
|
|
|
|
|
+ // standard in RFC-1213
|
|
|
|
+ static final OID interfacesTable = new OID(".1.3.6.1.2.1.2.2.1");
|
|
|
|
+
|
|
|
|
+ public static void setUp() throws Exception {
|
|
|
|
+
|
|
|
|
+ SNMP agent = new SNMP("0.0.0.0/161");
|
|
|
|
+ agent.start();
|
|
|
|
+
|
|
|
|
+ MOTableBuilder builder = new MOTableBuilder(interfacesTable)
|
|
|
|
+ .addColumnType(SMIConstants.SYNTAX_INTEGER, MOAccessImpl.ACCESS_READ_ONLY)
|
|
|
|
+ .addColumnType(SMIConstants.SYNTAX_OCTET_STRING,MOAccessImpl.ACCESS_READ_ONLY)
|
|
|
|
+ .addColumnType(SMIConstants.SYNTAX_INTEGER,MOAccessImpl.ACCESS_READ_ONLY)
|
|
|
|
+ .addColumnType(SMIConstants.SYNTAX_INTEGER,MOAccessImpl.ACCESS_READ_ONLY)
|
|
|
|
+ .addColumnType(SMIConstants.SYNTAX_GAUGE32,MOAccessImpl.ACCESS_READ_ONLY)
|
|
|
|
+ .addColumnType(SMIConstants.SYNTAX_OCTET_STRING,MOAccessImpl.ACCESS_READ_ONLY)
|
|
|
|
+ .addColumnType(SMIConstants.SYNTAX_INTEGER,MOAccessImpl.ACCESS_READ_ONLY)
|
|
|
|
+ .addColumnType(SMIConstants.SYNTAX_INTEGER,MOAccessImpl.ACCESS_READ_ONLY)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ .addRowValue(new Integer32(1))
|
|
|
|
+ .addRowValue(new OctetString("loopback"))
|
|
|
|
+ .addRowValue(new Integer32(24))
|
|
|
|
+ .addRowValue(new Integer32(1500))
|
|
|
|
+ .addRowValue(new Gauge32(10000000))
|
|
|
|
+ .addRowValue(new OctetString("00:00:00:00:01"))
|
|
|
|
+ .addRowValue(new Integer32(1500))
|
|
|
|
+ .addRowValue(new Integer32(1500))
|
|
|
|
+//next row
|
|
|
|
+ .addRowValue(new Integer32(2))
|
|
|
|
+ .addRowValue(new OctetString("eth0"))
|
|
|
|
+ .addRowValue(new Integer32(24))
|
|
|
|
+ .addRowValue(new Integer32(1500))
|
|
|
|
+ .addRowValue(new Gauge32(10000000))
|
|
|
|
+ .addRowValue(new OctetString("00:00:00:00:02"))
|
|
|
|
+ .addRowValue(new Integer32(1500))
|
|
|
|
+ .addRowValue(new Integer32(1500));
|
|
|
|
+
|
|
|
|
+ agent.registerManagedObject(builder.build());
|
|
|
|
+
|
|
|
|
+// Setup the client to use our newly started agent
|
|
|
|
+ //client = new SimpleSnmpClient("udp:127.0.0.1/2001");
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
-}
|
|
|