184 points · by guiambros · 4y ago · 59 comments
https://github.com/jaysoffian/eap_proxy/blob/78a058ffe67c253...
The dnspython package is pure python and it's a lot of code, but it supports pretty much everything related to DNS:
Just blindly copying flags off of a packet isn't really a good practice for software development. What if the packet was not recursive? I'm sure 99.99% of the people reading that have no idea that non-recursive packets were possible, or even what it means.
Instead, read RFC 4.1.1 and figure out what the flags mean and why you'd use one or the other.
https://www.rfc-editor.org/rfc/rfc1035
And by reading the actual format document you can start looking for vulnerabilities. For example, what happens when the various COUNT numbers aren't correct in a response? What if you get an error response code but there is response data? What if the implementor used signed instead of unsigned numbers for COUNT?
This is a bit better than SO, but not by much. You're not writing a DNS query, you're hacking someone else's DNS query and sending it over the wire.
compared to Python, Ruby has:
- first-class symbols (yes python has sys.intern but it would take a PEP giving them a pithy syntax to make them usable, plus python has 25 years of stdlib and libraries using "strings" or enums for constants instead of :symbols)
- procs/blocks and better-than-python lambdas
- "open classes" / monkey-patching of builtins (for better or for worse)
- trivial metaprogramming with method_missing (for better or for worse)
some of these make fun one-off projects easier or faster, some of them would be less welcome in large, mature codebases.But just to be a bit contrary:
- I don't see a huge value in symbols. In Ruby they are literally just static strings which means they use memory you'll never get back – potentially important if you're e.g. parsing something large into a hash and symbolizing the keys. If you have to put a non-alphanumeric character in a symbol you still need to use quotes.
- Procs, blocks, and lambdas – yes.
- Metaprogramming and monkey patching? dfjasdjldfjkdfjlkfdjldfoh4houfhufl. A double edged sword at best and 100% not something I'd want to see in a larger codebase. Javascript folks largely learned this lesson with the shift from Prototype to jQuery. You can do some really neat-o things but they're almost always unintuitive to the uninitiated.
the real footgun is dependencies that monkey patch things you don't know about / don't expect, and then the order you require those dependencies becomes important. augughghhhhh I hate that part.
I get it that the hype around Ruby and Rails has—thankfully—subsided but Ruby is even better today than it was then.
Sure when it was hype a decade ago you'd get lots of flashy tools and library every other days, but a large part of it was really wonky.
Now that the dust settled, the tools that remain largely used are much higher quality.
Ruby gets results.
This is not the case today. And most of those startups also had to then migrate to Go/Java/etc. to scale.
A bit of rant - what annoys me on similar "examples" like articles - those have none to 0 error handling and not even assuming things may go bad. Doing bind() with hope it will always succeed, connect without timeout - for me as a newbie such things are important to be provided in examples as well.
-Carl Sagan
With that said, it was cool to see a lower-level explanation than just calling a library.
DOH_SERVER=eu1.lavate.ch
(echo example.net;echo example.org;echo example.com) > 1.txt
yy048 < 1.txt|yy049|yy050|sed "s,.*,https://$DOH_SERVER?dns-query?dns=&," \
|yy025|openssl s_client -connect $DOH_SERVER:443 -ign_eof
This uses HTTP/1.1 pipelining and only a single TCP connection. Good netiquette.Instead of openssl one can use, e.g., stunnel, or an https proxy, plus netcat.
The sources for yy025, yy048, yy049 and yy050 are just short text files compiled with flex. If preferred, yy025 can be replaced a little more shell script and tr(1).
No Ruby, no Python, no Go, or other large languages. Just shell utilities.
Parsing catenated responses can be done with ldns, e.g., drill.
and the HTML source also includes a machine-readable element:
<p class="meta">
<time datetime="2022-11-06T08:31:53" pubdate="" data-updated="true"></time>
</p>
For my own journal, I tuck human-readable metadata inside a <details> block (which defaults to hidden), with the title in the nested <summary> (which defaults to visible). Thus, it's available, if visitors activate the title to reveal it.The world may be a better place without SEO.
Further, this code implements a stub resolver querying 8.8.8.8 --- in that scenario, there is no DNSSEC verification, as you know. For stub resolvers, the kind your browser or OS uses, DNSSEC condenses down to a single bit in the header that the server uses to say "trust me, I did DNSSEC".
> Further, this code implements a stub resolver
Fair enough, but…
> DNSSEC condenses down to a single bit in the header that the server uses to say "trust me, I did DNSSEC".
…they did not ask (in the query) for DNSSEC verification, nor did they check the bit in the response.
But HTTP without HTTPS is useful if you need to go really fast, same goes for taking DNS out of the loop and going straight to the IP.
The way I see it, it's all about your threat model. Who/what are you defending against.