I am trying to remove the <td> and </td> from a curl output. The output gives a table view that looks like this:
If DB were ready, would have added:
<table>
<tr>
<td>Title:</td>
<td>dsf</td>
</tr>
<tr>
<td>CWE:</td>
<td>SSBBTSBTT01FIEJBU0U2NAo=</td>
</tr>
<tr>
<td>Score:</td>
<td>fdsf</td>
</tr>
<tr>
<td>Reward:</td>
<td>dsfsdf</td>
</tr>
</table>
Under the CWE: column is some base64 I want to decode. Here is what I have tried:
#!/bin/bash
cp xxe.txt staging.txt
sed -i "s/PLACEHOLDER/$1/g" staging.txt
DATA=$(cat staging.txt|base64)
curl -X POST --data-urlencode "data=$DATA" -s http://10.10.11.100/tracker_diRbPr00f314.php > file
# sed: -e expression #1, char 9: unknown option to `s'
cat file | grep "<td>" | sed 's/<td>//g'| sed 's/</td>//g' | sed '1,3d' | sed '2,5d' | tr -d " "
Only, I keep getting
sed: -e expression #1, char 9: unknown option to `s'
on the cat file line.
Update: Using xmllint
#!/bin/bash
cp xxe.txt staging.txt
sed -i "s/PLACEHOLDER/$1/g" staging.txt
DATA=$(cat staging.txt|base64)
curl -X POST --data-urlencode "data=$DATA" -s http://10.10.11.100/tracker_diRbPr00f314.php > file
xmllint --html --xpath /table/tbody/tr[2]/td[2] $(cat file|sed '1,1d')
Gives me this:
warning: failed to load external entity "<table>"
warning: failed to load external entity "<tr>"
warning: failed to load external entity "<td>Title:</td>"
warning: failed to load external entity "<td>dsf</td>"
warning: failed to load external entity "</tr>"
warning: failed to load external entity "<tr>"
warning: failed to load external entity "<td>CWE:</td>"
warning: failed to load external entity "<td>BASE 64 WOULD BE HERE</td>"
warning: failed to load external entity "</tr>"
warning: failed to load external entity "<tr>"
warning: failed to load external entity "<td>Score:</td>"
warning: failed to load external entity "<td>fdsf</td>"
warning: failed to load external entity "</tr>"
warning: failed to load external entity "<tr>"
warning: failed to load external entity "<td>Reward:</td>"
warning: failed to load external entity "<td>dsfsdf</td>"
warning: failed to load external entity "</tr>"
warning: failed to load external entity "</table>"
Update more:
curl -X POST --data-urlencode "data=$DATA" -s http://10.10.11.100/tracker_diRbPr00f314.php | sed '1, 1d' | xmllint --html --xpath /table/tbody/tr[2]/td[2] -
XPath set is empty
xmllintand similar tools that can be run from the command line. See f/e xmllint to parse a html filexmllint --html --xpath /table/tbody/tr[2]/td[2] $(cat file)isn't working @CharlesDuffy$(cat file)? Of course it wouldn't work -- that reads your input file, breaks it into individual command line arguments and puts them on xmllint's command line. Why would you ever want to do that? Use the linked question's answers the way it says to use them, don't make up your own broken thing and then ask why it's broken.If DB were ready ... </table>, we don't have the matching expected output; please update the question with the expected output