Skip to content

Commit

Permalink
Fixed loging in MQTT packets.
Browse files Browse the repository at this point in the history
  • Loading branch information
irinil committed Jul 9, 2020
1 parent 1a48aa5 commit b2be626
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
Expand Up @@ -145,7 +145,7 @@ public void run() {
if (ConnectionGuard.portscanInProgress())
return;

//isTopicPublished(); //The record wont get updated.
isTopicPublished(); //The record wont get updated.
if(MQTTHandler.isAnAttackOngoing()) {
startHandler();
conReg.newOpenConnection();
Expand Down
Expand Up @@ -364,6 +364,7 @@ private synchronized AttackRecord createAttackRecord(AttackRecord existingRecord
record.setBssid(existingRecord.getBssid());
record.setSync_id(existingRecord.getSync_id());
record.setDevice(existingRecord.getDevice());

return record;
}

Expand Down Expand Up @@ -529,7 +530,6 @@ public ArrayList<MessageRecord> addMessageRecordFields(ArrayList<AttackRecord> a
}

public ArrayList<AttackRecord> addNetworkFields(ArrayList<AttackRecord> attackRecords,ArrayList<NetworkRecord> networkRecords){

ArrayList<AttackRecord > updatedAttackRecords = new ArrayList<>();
NetworkRecord current = new NetworkRecord();

Expand Down Expand Up @@ -644,6 +644,19 @@ public synchronized ArrayList<RecordAll> getAllRecords(){

}

public AttackRecord getMatchingAttackRecord(MessageRecord record){
AttackRecordDao recordDao = this.daoSession.getAttackRecordDao();
QueryBuilder<AttackRecord> qb = recordDao.queryBuilder();
try {
qb.where(AttackRecordDao.Properties.Attack_id.eq(record.getAttack_id()));
return qb.list().get(0);

}catch (Exception e){
return new AttackRecord();
}

}

/**
* Gets a single {@link Record} with the given attack id from the database.
*
Expand Down
Expand Up @@ -56,7 +56,7 @@ public MessageRecord getLastedInsertedRecord(){
MessageRecord record = new MessageRecord();

List<MessageRecord> messageRecords = recordDao.queryBuilder()
.orderAsc(MessageRecordDao.Properties.Id)
.orderDesc(MessageRecordDao.Properties.Id)
.limit(1)
.list();
if(!messageRecords.isEmpty()){
Expand Down
Expand Up @@ -45,6 +45,8 @@ public class MQTTHandler {
private static ArrayList<InterceptAcknowledgedMessage> interceptAcknowledgedMessages = new ArrayList<>();

private final static int brokerPort = 1883;
private static String packet = "";


/**
* Intercepts all the captured packets from the broker and adds the to the appropriate list.
Expand Down Expand Up @@ -170,12 +172,13 @@ public static void isTopicPublished(){
if(isAnAttackerConnected){
if(!currentPublishMessages.isEmpty()) {
DaoSession dbSession = HostageApplication.getInstances().getDaoSession();

DAOHelper daoHelper = new DAOHelper(dbSession);
MessageRecord record = daoHelper.getMessageRecordDAO().getLastedInsertedRecord();
record.setPacket(getPublishedTopics());
daoHelper.getMessageRecordDAO().updateRecord(record);

AttackRecord attackRecord = daoHelper.getAttackRecordDAO().getMatchingAttackRecord(record);
if(attackRecord.getProtocol().equals("MQTT")) {//prevents to change packets content accidentally when two simultaneously attacks occur.
record.setPacket(getPublishedTopics());
daoHelper.getMessageRecordDAO().updateRecord(record);
}
currentPublishMessages.clear();
}
}
Expand Down Expand Up @@ -220,19 +223,18 @@ private static String getIPCurrentClient() {
}

private static String getPublishedTopics(){
String packet = "";

if(!currentPublishMessages.isEmpty()){
InterceptPublishMessage message = currentPublishMessages.get(0);
if(message!=null) {
if (message.getClientID().equals(interceptConnectMessages.get(interceptConnectMessages.size()-1).getClientID())) {

packet+="TopicName: "+message.getTopicName()+" "+
"Message Clientid: "+message.getClientID()+
for(InterceptPublishMessage message:currentPublishMessages) {
if (message != null && !message.getClientID().equals(SensorProfile.getClientID())) {
if (message.getClientID().equals(interceptConnectMessages.get(interceptConnectMessages.size() - 1).getClientID())) {
packet += "TopicName: " + message.getTopicName() + " " +
"Message Clientid: " + message.getClientID() +
"/n";
return packet;

}
}

}
}
return packet;
}
Expand Down

0 comments on commit b2be626

Please sign in to comment.