Skip to main content

API Endpoints

While scrolling twitter recently I saw Intigriti linked to some JavaScript bookmarklet for discovering API endpoints. When doing reconnaissance, sometimes tools like ffuf aren't fine-grained enough for enumerating API endpoints. On the contrary however, interacting with an app in the browser is much more personal and can often reveal API endpoints other tools might miss. We can use the browser developer console and JavaScript to our advantage here:

(function () {
  const scripts = document.getElementsByTagName("script");
  const regex = /(?<=(\"|\'|\`))\/[a-zA-Z0-9_?&=\/\-\#\.]*(?=(\"|\'|\`))/g;
  const results = new Set();

  for (let i = 0; i < scripts.length; i++) {
    const src = scripts[i].src;
    if (src !== "") {
      fetch(src)
        .then((response) => response.text())
        .then((text) => {
          const matches = text.matchAll(regex);
          for (const match of matches) {
            results.add(match[0]);
          }
        })
        .catch((error) => {
          console.log("An error occurred: ", error);
        });
    }
  }

  const pageContent = document.documentElement.outerHTML;
  const pageMatches = pageContent.matchAll(regex);
  for (const match of pageMatches) {
    results.add(match[0]);
  }

  function writeResults() {
    results.forEach((result) => {
      document.write(result + "
"); }); } setTimeout(writeResults, 3000); })();

Gist on github here.

Comments

Popular posts from this blog

yt-dlp Archiving, Improved

One annoying thing about YouTube is that, by default, some videos are now served in .webm format or use VP9 encoding. However, I prefer storing media in more widely supported codecs and formats, like .mp4, which has broader support and runs on more devices than .webm files. And sometimes I prefer AVC1 MP4 encoding because it just works out of the box on OSX with QuickTime, as QuickTime doesn't natively support VP9/VPO9. AVC1-encoded MP4s are still the most portable video format. AVC1 ... is by far the most commonly used format for the recording, compression, and distribution of video content, used by 91% of video industry developers as of September 2019. [ 1 ] yt-dlp , the command-line audio/video downloader for YouTube videos, is a great project. But between YouTube supporting various codecs and compatibility issues with various video players, this can make getting what you want out of yt-dlp a bit more challenging: $ yt-dlp -f "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best...