|
@@ -146,28 +146,30 @@ public class SyncUtils {
|
|
|
public static void appendRecordToStringWriter(Record record, Writer stream){
|
|
|
try {
|
|
|
stream.append(
|
|
|
- "{" +
|
|
|
- "\"sensor\":{" +
|
|
|
- "\"name\":\"HosTaGe\"," +
|
|
|
- "\"type\":\"Honeypot\"" +
|
|
|
- "}," +
|
|
|
- "\"src\":{" +
|
|
|
- "\"ip\":\"" + record.getRemoteIP() + "\"," +
|
|
|
- "\"port\":" + record.getRemotePort() +
|
|
|
- "}," +
|
|
|
- "\"dst\":{" +
|
|
|
- "\"ip\":\"" + record.getExternalIP() /*record.getLocalIP()*/ + "\"," +
|
|
|
- "\"port\":" + record.getLocalPort() +
|
|
|
- "}," +
|
|
|
- "\"type\":" + (protocolsTypeMap.containsKey(record.getProtocol()) ? protocolsTypeMap.get(record.getProtocol()) : 0) + "," +
|
|
|
- "\"log\":\"" + record.getProtocol() + "\"," +
|
|
|
- "\"md5sum\":\"\"," +
|
|
|
- "\"date\":" + (int)(record.getTimestamp() / 1000) + "," +
|
|
|
- "\"bssid\":\"" + record.getBssid() + "\"," +
|
|
|
- "\"ssid\":\"" + record.getSsid() + "\"," +
|
|
|
- "\"device\":\"" + record.getDevice() + "\"," +
|
|
|
- "\"sync_id\":\"" + record.getSync_id() + "\"" +
|
|
|
- "}\n"
|
|
|
+ "{" +
|
|
|
+ "\"sensor\":{" +
|
|
|
+ "\"name\":\"HosTaGe\"," +
|
|
|
+ "\"type\":\"Honeypot\"" +
|
|
|
+ "}," +
|
|
|
+ "\"src\":{" +
|
|
|
+ "\"ip\":\"" + record.getRemoteIP() + "\"," +
|
|
|
+ "\"port\":" + record.getRemotePort() +
|
|
|
+ "}," +
|
|
|
+ "\"dst\":{" +
|
|
|
+ "\"ip\":\"" + record.getLocalIP() + "\"," +
|
|
|
+ "\"port\":" + record.getLocalPort() +
|
|
|
+ "}," +
|
|
|
+ "\"type\":" + (protocolsTypeMap.containsKey(record.getProtocol()) ? protocolsTypeMap.get(record.getProtocol()) : 0) + "," +
|
|
|
+ "\"log\":\"" + record.getProtocol() + "\"," +
|
|
|
+ "\"md5sum\":\"\"," +
|
|
|
+ "\"date\":" + (int)(record.getTimestamp() / 1000) + "," +
|
|
|
+ "\"bssid\":\"" + record.getBssid() + "\"," +
|
|
|
+ "\"ssid\":\"" + record.getSsid() + "\"," +
|
|
|
+ "\"device\":\"" + record.getDevice() + "\"," +
|
|
|
+ "\"sync_id\":\"" + record.getSync_id() + "\"," +
|
|
|
+ "\"internal_attack\":\"" + record.getWasInternalAttack() + "\"," +
|
|
|
+ "\"external_ip\":\"" + record.getExternalIP() + "\"" +
|
|
|
+ "}\n"
|
|
|
);
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
@@ -262,31 +264,31 @@ public class SyncUtils {
|
|
|
JSONObject condition = new JSONObject();
|
|
|
|
|
|
/**if(fromTime > 0){
|
|
|
- Calendar calendar = GregorianCalendar.getInstance();
|
|
|
- calendar.setTimeInMillis(fromTime);
|
|
|
+ Calendar calendar = GregorianCalendar.getInstance();
|
|
|
+ calendar.setTimeInMillis(fromTime);
|
|
|
|
|
|
- condition.put("date", fromCalendar(calendar));
|
|
|
- }**/
|
|
|
+ condition.put("date", fromCalendar(calendar));
|
|
|
+ }**/
|
|
|
|
|
|
/**
|
|
|
- TODO(alex): UNCOMMENT THIS AGAIN, WHEN WE ARE SURE ABOUT USING LOCATIONS THIS WAY.
|
|
|
- =======================================================================
|
|
|
+ TODO(alex): UNCOMMENT THIS AGAIN, WHEN WE ARE SURE ABOUT USING LOCATIONS THIS WAY.
|
|
|
+ =======================================================================
|
|
|
|
|
|
- Location location = MyLocationManager.getNewestLocation();
|
|
|
- if(location != null){
|
|
|
- JSONArray ll = new JSONArray();
|
|
|
- ll.put(location.getLongitude());
|
|
|
- ll.put(location.getLatitude());
|
|
|
+ Location location = MyLocationManager.getNewestLocation();
|
|
|
+ if(location != null){
|
|
|
+ JSONArray ll = new JSONArray();
|
|
|
+ ll.put(location.getLongitude());
|
|
|
+ ll.put(location.getLatitude());
|
|
|
|
|
|
- condition.put("location", ll);
|
|
|
- condition.put("distance", 500);
|
|
|
- } else {
|
|
|
- // We could not get the gps coordinates, try to retrieve the country code from the SIM card
|
|
|
- TelephonyManager tm = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
|
|
|
- String countryCodeValue = tm.getNetworkCountryIso();
|
|
|
+ condition.put("location", ll);
|
|
|
+ condition.put("distance", 500);
|
|
|
+ } else {
|
|
|
+ // We could not get the gps coordinates, try to retrieve the country code from the SIM card
|
|
|
+ TelephonyManager tm = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
|
|
|
+ String countryCodeValue = tm.getNetworkCountryIso();
|
|
|
|
|
|
- condition.put("country", countryCodeValue);
|
|
|
- }*/
|
|
|
+ condition.put("country", countryCodeValue);
|
|
|
+ }*/
|
|
|
|
|
|
JSONObject req = new JSONObject();
|
|
|
req.put("condition", condition);
|
|
@@ -351,8 +353,8 @@ public class SyncUtils {
|
|
|
record.setLocalPort(dst.getInt("port"));
|
|
|
record.setRemoteIP(src.getString("ip"));
|
|
|
record.setRemotePort(src.getInt("port"));
|
|
|
- record.setExternalIP("0.0.0.0");
|
|
|
- record.setWasInternalAttack(false);
|
|
|
+ record.setExternalIP(item.has("external_ip") ? item.getString("external_ip") : "0.0.0.0");
|
|
|
+ record.setWasInternalAttack(item.has("internal_attack") && item.getBoolean("internal_attack"));
|
|
|
|
|
|
syncRecords.add(record);
|
|
|
} catch(Exception e){
|
|
@@ -404,8 +406,8 @@ public class SyncUtils {
|
|
|
}
|
|
|
|
|
|
sb.append(String.format("%s=%s",
|
|
|
- urlEncodeUTF8(query[i]),
|
|
|
- urlEncodeUTF8(query[i + 1])
|
|
|
+ urlEncodeUTF8(query[i]),
|
|
|
+ urlEncodeUTF8(query[i + 1])
|
|
|
));
|
|
|
}
|
|
|
|
|
@@ -418,8 +420,8 @@ public class SyncUtils {
|
|
|
|
|
|
public static String buildUrl(String protocol, String domain, int port, String path, String ... query){
|
|
|
return buildUrlFromBase(
|
|
|
- String.format("%s://%s:%d/%s", urlEncodeUTF8(protocol), urlEncodeUTF8(domain), port, path),
|
|
|
- query
|
|
|
+ String.format("%s://%s:%d/%s", urlEncodeUTF8(protocol), urlEncodeUTF8(domain), port, path),
|
|
|
+ query
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -515,4 +517,4 @@ public class SyncUtils {
|
|
|
return new DefaultHttpClient();
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
+}
|