Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Matrix
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Operate
Environments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Matrix
Commits
1b2067f5
Commit
1b2067f5
authored
5 years ago
by
Erik Johnston
Browse files
Options
Downloads
Patches
Plain Diff
Add FileExfiltrationWriter
parent
e8c53b07
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
synapse/app/admin_cmd.py
+69
-1
69 additions, 1 deletion
synapse/app/admin_cmd.py
with
69 additions
and
1 deletion
synapse/app/admin_cmd.py
+
69
−
1
View file @
1b2067f5
...
...
@@ -15,7 +15,11 @@
# limitations under the License.
import
argparse
import
logging
import
os
import
sys
import
tempfile
from
canonicaljson
import
json
from
twisted.internet
import
defer
,
task
...
...
@@ -24,7 +28,7 @@ from synapse.app import _base
from
synapse.config._base
import
ConfigError
from
synapse.config.homeserver
import
HomeServerConfig
from
synapse.config.logger
import
setup_logging
from
synapse.handlers.admin
import
File
ExfiltrationWriter
from
synapse.handlers.admin
import
ExfiltrationWriter
from
synapse.replication.slave.storage._base
import
BaseSlavedStore
from
synapse.replication.slave.storage.account_data
import
SlavedAccountDataStore
from
synapse.replication.slave.storage.appservice
import
SlavedApplicationServiceStore
...
...
@@ -107,6 +111,70 @@ def export_data_command(hs, args):
print
(
res
)
class
FileExfiltrationWriter
(
ExfiltrationWriter
):
"""
An ExfiltrationWriter that writes the users data to a directory.
Returns the directory location on completion.
Note: This writes to disk on the main reactor thread.
Args:
user_id (str): The user whose data is being exfiltrated.
directory (str|None): The directory to write the data to, if None then
will write to a temporary directory.
"""
def
__init__
(
self
,
user_id
,
directory
=
None
):
self
.
user_id
=
user_id
if
directory
:
self
.
base_directory
=
directory
else
:
self
.
base_directory
=
tempfile
.
mkdtemp
(
prefix
=
"
synapse-exfiltrate__%s__
"
%
(
user_id
,)
)
os
.
makedirs
(
self
.
base_directory
,
exist_ok
=
True
)
if
list
(
os
.
listdir
(
self
.
base_directory
)):
raise
Exception
(
"
Directory must be empty
"
)
def
write_events
(
self
,
room_id
,
events
):
room_directory
=
os
.
path
.
join
(
self
.
base_directory
,
"
rooms
"
,
room_id
)
os
.
makedirs
(
room_directory
,
exist_ok
=
True
)
events_file
=
os
.
path
.
join
(
room_directory
,
"
events
"
)
with
open
(
events_file
,
"
a
"
)
as
f
:
for
event
in
events
:
print
(
json
.
dumps
(
event
.
get_pdu_json
()),
file
=
f
)
def
write_state
(
self
,
room_id
,
event_id
,
state
):
room_directory
=
os
.
path
.
join
(
self
.
base_directory
,
"
rooms
"
,
room_id
)
state_directory
=
os
.
path
.
join
(
room_directory
,
"
state
"
)
os
.
makedirs
(
state_directory
,
exist_ok
=
True
)
event_file
=
os
.
path
.
join
(
state_directory
,
event_id
)
with
open
(
event_file
,
"
a
"
)
as
f
:
for
event
in
state
.
values
():
print
(
json
.
dumps
(
event
.
get_pdu_json
()),
file
=
f
)
def
write_invite
(
self
,
room_id
,
event
,
state
):
self
.
write_events
(
room_id
,
[
event
])
# We write the invite state somewhere else as they aren't full events
# and are only a subset of the state at the event.
room_directory
=
os
.
path
.
join
(
self
.
base_directory
,
"
rooms
"
,
room_id
)
os
.
makedirs
(
room_directory
,
exist_ok
=
True
)
invite_state
=
os
.
path
.
join
(
room_directory
,
"
invite_state
"
)
with
open
(
invite_state
,
"
a
"
)
as
f
:
for
event
in
state
.
values
():
print
(
json
.
dumps
(
event
),
file
=
f
)
def
finished
(
self
):
return
self
.
base_directory
def
start
(
config_options
):
parser
=
argparse
.
ArgumentParser
(
description
=
"
Synapse Admin Command
"
)
HomeServerConfig
.
add_arguments_to_parser
(
parser
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment