Skip to content

Commit

Permalink
another update
Browse files Browse the repository at this point in the history
  • Loading branch information
caffix committed Nov 29, 2024
1 parent dfa9d63 commit 81dd4a4
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions initdb-assetdb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,18 @@ psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$AMASS_DB" <<-EOSQ
FOR _var_r IN (
SELECT srvs.content->>'name' AS "name", ips.content->>'address' AS "addr"
FROM ((((entities AS fqdns INNER JOIN edges AS r1 ON fqdns.id = r1.from_entity_id)
INNER JOIN entities AS srvs ON r1.to_entity_id = srvs.id) INNER JOIN edges AS r2 ON srvs.id =
r2.from_entity_id) INNER JOIN entities AS ips ON r2.to_entity_id = ips.id)
FROM ((((entities AS fqdns
INNER JOIN edges AS r1 ON fqdns.entity_id = r1.from_entity_id)
INNER JOIN entities AS srvs ON r1.to_entity_id = srvs.id)
INNER JOIN edges AS r2 ON srvs.entity_id = r2.from_entity_id)
INNER JOIN entities AS ips ON r2.to_entity_id = ips.entity_id)
WHERE fqdns.etype = 'FQDN' AND srvs.etype = 'FQDN' AND ips.etype = 'IPAddress'
AND r1.etype IN ('PrefDNSRelation', 'SRVDNSRelation') AND r2.etype = 'BasicDNSRelation'
AND r1.content->>'label' = 'dns_record' AND r2.content->>'label' = 'dns_record'
AND r1.content->>'header.rr_type' IN (33, 2, 15) AND r2.content->>'header.rr_type' IN (1, 28)
AND r1.updated_at >= _from AND r1.updated_at <= _to AND r2.updated_at >= _from AND r2.updated_at <= _to
AND fqdns.content->>'name' = ANY(_names)
AND r1.etype IN ('PrefDNSRelation', 'SRVDNSRelation') AND r1.content->>'label' = 'dns_record'
AND r1.content->>'header.rr_type' IN ('33', '2', '15')
AND r2.etype = 'BasicDNSRelation' AND r2.content->>'label' = 'dns_record'
AND r2.content->>'header.rr_type' IN ('1', '28')
AND r1.updated_at >= _from AND r1.updated_at <= _to AND r2.updated_at >= _from
AND r2.updated_at <= _to AND fqdns.content->>'name' = ANY(_names)
) LOOP fqdn = _var_r.name;
ip_addr = _var_r.addr;
_names = array_remove(_names, _var_r.name);
Expand All @@ -55,11 +58,11 @@ psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$AMASS_DB" <<-EOSQ
FOR _var_r IN (
SELECT fqdns.content->>'name' AS "name", ips.content->>'address' AS "addr"
FROM ((entities AS fqdns
INNER JOIN edges ON fqdns.id = edges.from_entity_id)
INNER JOIN entities AS ips ON edges.to_entity_id = ips.id)
INNER JOIN edges ON fqdns.entity_id = edges.from_entity_id)
INNER JOIN entities AS ips ON edges.to_entity_id = ips.entity_id)
WHERE fqdns.etype = 'FQDN' AND ips.etype = 'IPAddress'
AND edges.etype = 'BasicDNSRelation' AND edges.content->>'label' = 'dns_record'
AND edges.content->>'header.rr_type' IN (1, 28) AND edges.updated_at >= _from
AND edges.content->>'header.rr_type' IN ('1', '28') AND edges.updated_at >= _from
AND edges.updated_at <= _to AND fqdns.content->>'name' = ANY(_names)
) LOOP fqdn = _var_r.name;
ip_addr = _var_r.addr;
Expand All @@ -73,20 +76,20 @@ psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$AMASS_DB" <<-EOSQ
VALUES(_name)
UNION
SELECT cnames.content->>'name' FROM ((entities AS fqdns
INNER JOIN edges ON fqdns.id = edges.from_entity_id)
INNER JOIN entities AS cnames ON edges.to_entity_id = cnames.id), traverse_cname
INNER JOIN edges ON fqdns.entity_id = edges.from_entity_id)
INNER JOIN entities AS cnames ON edges.to_entity_id = cnames.entity_id), traverse_cname
WHERE fqdns.etype = 'FQDN' AND cnames.etype = 'FQDN'
AND edges.updated_at >= _from AND edges.updated_at <= _to
AND edges.etype = 'BasicDNSRelation' AND edges.content->>'label' = 'dns_record'
AND edges.content->>'header.rr_type' = 5
AND edges.content->>'header.rr_type' = '5'
AND fqdns.content->>'name' = traverse_cname._fqdn)
SELECT fqdns.content->>'name' AS "name", ips.content->>'address' AS "addr"
FROM ((entities AS fqdns INNER JOIN edges ON fqdns.id = edges.from_entity_id)
INNER JOIN entities AS ips ON edges.to_entity_id = ips.id)
FROM ((entities AS fqdns INNER JOIN edges ON fqdns.entity_id = edges.from_entity_id)
INNER JOIN entities AS ips ON edges.to_entity_id = ips.entity_id)
WHERE fqdns.etype = 'FQDN' AND ips.etype = 'IPAddress'
AND edges.updated_at >= _from AND edges.updated_at <= _to
AND edges.etype = 'BasicDNSRelation' AND edges.content->>'label' = 'dns_record'
AND edges.content->>'header.rr_type' IN (1, 28)
AND edges.content->>'header.rr_type' IN ('1', '28')
AND fqdns.content->>'name' IN (SELECT _fqdn FROM traverse_cname)
) LOOP fqdn = _name;
ip_addr = _var_r.addr;
Expand Down

0 comments on commit 81dd4a4

Please sign in to comment.