CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/msf/core/exploit/riff.rb
Views: 11623
1
# -*- coding: binary -*-
2
3
module Msf
4
5
###
6
#
7
# This module provides some functions for dealing with MCI RIFF data
8
#
9
###
10
11
module Exploit::RIFF
12
13
#
14
# Builds a RIFF chunk with a specified tag and data
15
#
16
def riff_chunk(tag, data)
17
18
len = data.length
19
padding = len % 2 # RIFF chunks must be 2 byte aligned
20
21
return tag + [len].pack('V') + data + ("\x00" * padding)
22
end
23
24
#
25
# Builds a RIFF list chunk (one containing other chunks)
26
#
27
def riff_list_chunk(tag, type, data)
28
29
len = data.length + 4
30
padding = len % 2
31
32
return tag + [len].pack('V') + type + data
33
end
34
35
#
36
# Generates a random number of random RIFF chunks, up to 4352 bytes
37
#
38
def random_riff_chunks(count = rand(16) + 17)
39
chunks = ''
40
41
0.upto(count) do
42
chunks << random_riff_chunk()
43
end
44
45
return chunks
46
end
47
48
#
49
# Generates a random RIFF chunk, up to 136 bytes
50
#
51
def random_riff_chunk(len = rand(128) + 1)
52
riff_chunk(random_riff_tag, rand_text(len))
53
end
54
55
56
#
57
# Generates a random RIFF tag, making sure that it's not one of the
58
# tags processed by LoadAniIcon or LoadCursorIconFromFileMap
59
#
60
def random_riff_tag
61
valid = ['RIFF', 'ACON', 'anih', 'LIST', 'fram', 'icon', 'rate']
62
63
tag = nil
64
begin
65
tag = rand_text_alpha(4)
66
end while valid.include? tag
67
68
return tag
69
end
70
71
end
72
73
end
74
75