Write script to run a command in (u)rxvt, and send the output to a text file?

For discussions about programming, and for programming questions and advice


Moderator: Forum moderators

Post Reply
User avatar
mikewalsh
Moderator
Posts: 6163
Joined: Tue Dec 03, 2019 1:40 pm
Location: King's Lynn, UK
Has thanked: 795 times
Been thanked: 1983 times

Write script to run a command in (u)rxvt, and send the output to a text file?

Post by mikewalsh »

Afternoon, gang.

I confess, I'm not entirely sure quite what I'm doing here.

On several occasions in the past, I've scripted an instance of rxvt to run, stay open, and execute a command to display the output. Which all works fine. However, I'm getting a wee bit stuck on this one.....whether it's old age playing tricks with the old grey matter, or I'm just having one of those days when it simply isn't functioning, I don't know.

Here's the scenario:-

termbin.com is a terminal-based pastebin, OK? The particular operation I want to try & script is this:-

You can run inxi, with whatever parameters you choose, send the output direct to termbin, and the output you get back is a URL to your data.....which anybody else can then view direct in their browser for trouble-shooting purposes.

If I run

Code: Select all

inxi -Fxzzr | nc termbin.com 9999

.....in the terminal (these are termbin's own instructions, right?), I get back a URL as output. As expected.

What I'd like to do is to run a script which will open (u)rxvt, run that command & get the URL back, followed by sending that output - the URL - to a text file. Sounds simple, right? But trying to implement it is proving a right royal PITA...!

Code: Select all

rxvt --hold -e inxi -Fxzzr | nc termbin.com 9999 > /tmp/report.txt

.....is not doing it. Any suggestions, guys? Where am I going wrong?

Mike. ;)

User avatar
fredx181
Posts: 3085
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 376 times
Been thanked: 1315 times
Contact:

Re: Write script to run a command in (u)rxvt, and send the output to a text file?

Post by fredx181 »

Hi Mike,
This should do:
rxvt --hold -e bash -c 'inxi -Fxzzr | nc termbin.com 9999 > /tmp/report.txt'
Or if you want to show the url in rxvt too (besides in /tmp/report.txt):
rxvt --hold -e bash -c 'inxi -Fxzzr | nc termbin.com 9999 | tee /tmp/report.txt'

williwaw
Posts: 1957
Joined: Tue Jul 14, 2020 11:24 pm
Has thanked: 172 times
Been thanked: 371 times

Re: Write script to run a command in (u)rxvt, and send the output to a text file?

Post by williwaw »

wouldnt you want to send the output of inxi to file, and send the file to termbin?

User avatar
mikewalsh
Moderator
Posts: 6163
Joined: Tue Dec 03, 2019 1:40 pm
Location: King's Lynn, UK
Has thanked: 795 times
Been thanked: 1983 times

Re: Write script to run a command in (u)rxvt, and send the output to a text file?

Post by mikewalsh »

@fredx181 :-

Thanks for that, Fred. That pretty much did the trick.....with a bit of modification.

The command now looks like this:-

Code: Select all

rxvt -ls -e bash -c '/usr/local/bin/inxi -Fxzzrc0 | nc termbin.com 9999 > /tmp/report.txt'

I've dropped the '-hold' option, since I don't want that terminal window open all the time. It stays open just long enough to run the command, upload the output to termbin, get the URL link back, and write that to a file in /tmp.....and then it closes. Moments later, a gxmessage window appears displaying the termbin.com URL, while a gtkdialog banner shows at the top of the screen & reminds the user to copy the URL before closing the gxmessage window.......because less than a second after closing gxmessage, the file in /tmp is deleted.

I've done it this way because trying to copy/paste to a browser URL bar with urxvt's middle-click function fails every time; with gxmessage, you CAN actually rt-click -> 'Copy'.

======================

@williwaw :-

I've done it like this because of differences between fora. Some don't care about bandwidth usage, and are happy for the full output to be pasted into a forum post in plain text. Other fora are quite fussy about wasting bandwidth unnecessarily; these prefer the pastebin link, because it's short & to the point, and the individual user only opens the output in their browser if they're interested .....and this way, sending the output direct via curl, it cuts down on the number of steps needed.

The reworked version can be found here:-

https://www.forum.puppylinux.com/viewtopic.php?t=10783

Mike. ;)

williams2
Posts: 1062
Joined: Sat Jul 25, 2020 5:45 pm
Been thanked: 305 times

Re: Write script to run a command in (u)rxvt, and send the output to a text file?

Post by williams2 »

Why open a new terminal window?
Just execute it as a line in the first script.
Like this:

Code: Select all

echo 'running a script ...'
echo 'running a script ...'
echo 'running a script ...'
inxi -Fxzzrc0 | nc termbin.com 9999 > /tmp/report.txt
echo 'running a script ...'
echo 'running a script ...'
echo 'running a script ...'

or something like this.

Code: Select all

defaultbrowser $(inxi -Fxzzrc0 | nc termbin.com 9999)

trying to copy/paste to a browser URL bar with urxvt's middle-click function fails every

In most Pups, urxvt automatically copies selected text to both
primary and clipboard buffers.
So select the text in urxvt to copy the text
then press ctrl+V to paste it to Geany, Firefox, etc.
couldn't be easier.

(ctrl+L to focus to the url bar. So,
select text, ctrl+L, ctrl+V)

Last edited by williams2 on Wed Oct 23, 2024 10:57 pm, edited 1 time in total.
User avatar
norgo
Posts: 283
Joined: Mon Jul 13, 2020 6:39 pm
Location: Germany
Has thanked: 6 times
Been thanked: 111 times
Contact:

Re: Write script to run a command in (u)rxvt, and send the output to a text file?

Post by norgo »

Hello @mikewalsh

here another application. https://github.com/theZiz/aha
Actually this app is doing the same like termbin.com.
The difference is, that you can write directly a html file and you can change the color.
It's often useful to turn background to black color because it is better readable.
You can read the file in a webbrowser or convert to pdf or whatever, I like it very much.

the commandline for your "inxi" example with black background

Code: Select all

inxi -Fxzzr | aha --black > ~/inxi.htm
aha_output_example.jpg
aha_output_example.jpg (104.58 KiB) Viewed 1538 times
Attachments
aha-0.5-x86_64.pet
(12.77 KiB) Downloaded 19 times
User avatar
mikewalsh
Moderator
Posts: 6163
Joined: Tue Dec 03, 2019 1:40 pm
Location: King's Lynn, UK
Has thanked: 795 times
Been thanked: 1983 times

Re: Write script to run a command in (u)rxvt, and send the output to a text file?

Post by mikewalsh »

@fredx181 / @williams2 :-

Okay; modified yet again. More files have been moved out of the 'DATA' sub-directory into the main one, and renamed; the tray icon script has been re-jigged to suit, as have some of the files themselves.

I've done away with the terminal altogether. Reading williams2's suggestions, I realised that I'd been trying all sorts of combinations earlier on; I had actually got a file to appear in /tmp WITH the info, BUT.....every other word or two, I'd got the word 'ESC' in a little black box, along with various combos of letters/numbers in square brackets, all muddled in with the output.

I initially thought I was doing something wrong.....and then I had a read through the 'options list' that I'd provided.....and realised what that 'c0' was that had been added onto the end of the 'filter list'. I.e:-

Code: Select all

-Fxzzr

.....becoming

Code: Select all

-Fxzzrc0

.....and so on, and so forth.

Inxi provides its terminal readout in different combinations of colours, to make it easier to read - somewhere around 40-odd different colour themes. I'd used one of them in the 'RUN' script's output command ('24').....but of course, this colour coding is all interspersed with the readout, and makes it all but impossible to read as a text file. So; 'c0' disables the colour theming - turns it off - along with all that superfluous code. Result? A clear, easy-to-read text file.

Which means that williams2's suggestion did in fact work as originally expected. 'Twas my own fault for not fully understanding what all that 'extra' coding every other word was.....but now that I do, Fred, the terminal stuff is effectively redundant. It's simply not needed.

The re-re-worked 'portable' is now uploaded to the original thread, as detailed a few posts back.....and is working very sweetly indeed.

Mike. :D

User avatar
mikewalsh
Moderator
Posts: 6163
Joined: Tue Dec 03, 2019 1:40 pm
Location: King's Lynn, UK
Has thanked: 795 times
Been thanked: 1983 times

Re: Write script to run a command in (u)rxvt, and send the output to a text file?

Post by mikewalsh »

@norgo :-

Heh. Ooh, that's very neat, mate. Works beautifully.

Am I right in thinking that anyone who wants to view your HTM file needs to have this installed.....or is it only used to actually generate the HTM file? In other words, the HTM file can be viewed anywhere, by anybody, and 'aha' won't be needed in order to view it?

Image

Notice I've used the same '-c 24' (colour theme) as I do in the portable's output command. Anyways; thanks for sharing. Cheers!

Mike. :thumbup:

User avatar
MochiMoppel
Posts: 1239
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 21 times
Been thanked: 440 times

Re: Write script to run a command in (u)rxvt, and send the output to a text file?

Post by MochiMoppel »

mikewalsh wrote: Wed Oct 23, 2024 9:15 pm

I've done it this way because trying to copy/paste to a browser URL bar with urxvt's middle-click function fails every time

???
Middle-click from urxvt or rxvt or any other selection source works for me. The browser's address field may have to be emptied first, which makes it a bit more tedious than pasting from clipboard, but it works.

@williams2 's proposal also works, but only in urxvt, not in rxvt and only if the perl extensions are implemented and configured accordingly. I wouldn't count on it.

User avatar
mikewalsh
Moderator
Posts: 6163
Joined: Tue Dec 03, 2019 1:40 pm
Location: King's Lynn, UK
Has thanked: 795 times
Been thanked: 1983 times

Re: Write script to run a command in (u)rxvt, and send the output to a text file?

Post by mikewalsh »

@MochiMoppel :-

MochiMoppel wrote: Thu Oct 24, 2024 1:51 am

???
Middle-click from urxvt or rxvt or any other selection source works for me. The browser's address field may have to be emptied first, which makes it a bit more tedious than pasting from clipboard, but it works.

@williams2 's proposal also works, but only in urxvt, not in rxvt and only if the perl extensions are implemented and configured accordingly. I wouldn't count on it.

In fact, it's not Puppy that's at fault here, Mochi. I've eventually figured out it's the VicTsing mouse I've been using for the last few months; it appears to have an intermittent, "iffy" contact under the scroll-wheel. Since the middle-click doesn't get used here that often, I overlook this one small issue because otherwise it's a very good mouse.

It just catches me out on the occasions when it decides to misbehave, because I keep forgetting it HAS this "downside"... :roll:

=============================

As for the inxi -> termbin command, I'm just using it directly in the 'inxi-report' script now.....with no (u)rxvt or other terminal involved at all. Despite being a terminal-based pastebin, it seems happy to run direct from a Bash script, too:-

Code: Select all

#!/bin/sh
#
# Send Inxi output to Termbin.com, and get readout URL...
#
inxi -Fxzzrc0 | nc termbin.com 9999 > /tmp/report.txt
#
/usr/lib/gtkdialog/box_splash -placement top -bg white -fg black -timeout 10 -text "  Copy URL BEFORE closing gxmessage window..! " &
sleep 0.25
#
gxmessage -bg yellow -fg black -name 'Termbin URL...' -center -file /tmp/report.txt
#
rm -f /tmp/report.txt
rm /usr/local/bin/inxi

Works for me.

Mike. Image

User avatar
fredx181
Posts: 3085
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 376 times
Been thanked: 1315 times
Contact:

Re: Write script to run a command in (u)rxvt, and send the output to a text file?

Post by fredx181 »

mikewalsh wrote: Thu Oct 24, 2024 9:59 am

Code: Select all

#!/bin/sh
..
rm /usr/local/bin/inxi

..

Why remove /usr/local/bin/inxi ? :thumbdown:

User avatar
MochiMoppel
Posts: 1239
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 21 times
Been thanked: 440 times

Re: Write script to run a command in (u)rxvt, and send the output to a text file?

Post by MochiMoppel »

mikewalsh wrote: Thu Oct 24, 2024 9:59 am

Works for me.

Last line reads rm /usr/local/bin/inxi :o Looks like your script will work only once :lol:
Did you try @williams2's proposal to send the URL generated by inxi -Fxzzrc0 | nc termbin.com 9999 directly to the browser, skipping the tempfile and gtkdialog and gxmessage detour?

[Edit] fredx181 posted while I was still writing, but I see that we have the same concerns ;)

User avatar
mikewalsh
Moderator
Posts: 6163
Joined: Tue Dec 03, 2019 1:40 pm
Location: King's Lynn, UK
Has thanked: 795 times
Been thanked: 1983 times

Re: Write script to run a command in (u)rxvt, and send the output to a text file?

Post by mikewalsh »

@fredx181 / @MochiMoppel :-

Heh. Yah; good catch, guys. That's not supposed to be there. Since posting that script a little bit earlier, I've re-jigged things quite a bit more.

I originally linked the 'inxi' script into /usr/local/bin, because the linked 'RUN' script for the portable's executable tray icon was also called 'inxi' as well (in /usr/bin). This has been renamed to 'inxi-portable', and since the main 'inxi' script is now being used from within the portable directory, it no longer needs to be linked-in at all.

'Twas done this way because initially, I couldn't make the termbin command 'see' the 'inxi' script inside the portable; it appeared to only want to search the main file-system /bins, so I figured it was just easier to link the inxi script into one of the bins as part of the 'Tray-Add' script. So that's what I did.

Now, this morning, it's doing what it should have done all along, and is using the main 'inxi' script directly from inside the portable. I was having "one of those days" yesterday when I first started figuring this termbin report thing out.....nothing seemed to want to do quite what it was supposed to! :roll: :lol:

Code: Select all

#!/bin/sh
#
# Send Inxi output to Termbin.com, and get readout URL...
#
HERE="$(dirname "$(readlink -f "$0")")"
#
$HERE/inxi -Fxzzrc0 | nc termbin.com 9999 > /tmp/report.txt
#
/usr/lib/gtkdialog/box_splash -placement top -bg white -fg black -timeout 10 -text "  Copy URL BEFORE closing gxmessage window..! " &
sleep 0.25
#
gxmessage -bg yellow -fg black -name 'Termbin URL...' -center -file /tmp/report.txt
#
rm -f /tmp/report.txt

=============================

I've added a small multi-launch GUI for anyone who wants to use this purely AS a 'portable' application. If the "Add tray icon" option is selected, the tray icon behaves as usual, launching the Inxi 'add options' GUI directly.

Yes, I know this is all awfully complicated for what is supposed to be just a simple, terminal-based application. But since it's the most commonly-requested diagnostic item on all the Linux fora that I belong to, I wanted to make it as simple as possible to use for any of our new Windows "refugees".

=============================

So; why don't I bypass the other stuff and open direct in the browser? I could, most certainly.....but for the simple reason that I didn't WANT to. I've seen my INXI readout so many times I'm sick of the sight of it, and I don't want to be opening it up in the browser every time it's requested. I'd rather just supply the URL direct; that way, only those who are interested in it will actually bother looking at it.

('Salright, guys; I know my approach often veers toward excessive over-complication, but I DO try to help make Puppy as accessible as possible for all......especially given that it's during the first days with a new operating system that most noobs NEED a certain amount of familiarity. I don't know of too many that dive straight into the terminal on their very first boot..! *shrug*)

Mike. ;)

User avatar
puppy_apprentice
Posts: 692
Joined: Tue Oct 06, 2020 8:43 pm
Location: land of bigos and schabowy ;)
Has thanked: 5 times
Been thanked: 115 times

Re: Write script to run a command in (u)rxvt, and send the output to a text file?

Post by puppy_apprentice »

I you need only URL that you can paste into the forum:

Code: Select all

cal | nc termbin.com 9999 | xclip

Code: Select all

cal | nc termbin.com 9999 | xclip -selection c

Terminal output to html:
https://github.com/masukomi/oho

User avatar
mikewalsh
Moderator
Posts: 6163
Joined: Tue Dec 03, 2019 1:40 pm
Location: King's Lynn, UK
Has thanked: 795 times
Been thanked: 1983 times

Re: Write script to run a command in (u)rxvt, and send the output to a text file?

Post by mikewalsh »

@puppy_apprentice :-

Hm. Looks rather similar in concept to 'aha', which norgo posted about a little further back in the thread. Good find, though..!

Mike. :thumbup:

User avatar
MochiMoppel
Posts: 1239
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 21 times
Been thanked: 440 times

Re: Write script to run a command in (u)rxvt, and send the output to a text file?

Post by MochiMoppel »

Instead of

Code: Select all

$HERE/inxi -Fxzzrc0 | nc termbin.com 9999 > /tmp/report.txt
/usr/lib/gtkdialog/box_splash -placement top -bg white -fg black -timeout 10 -text "  Copy URL BEFORE closing gxmessage window..! " &
sleep 0.25
gxmessage -bg yellow -fg black -name 'Termbin URL...' -center -file /tmp/report.txt
rm -f /tmp/report.txt

try

Code: Select all

gxmessage -bg yellow -fg black -name 'Termbin URL...' -center $'Copy URL BEFORE closing this  window..!\n'"$($HERE/inxi -Fxzzrc0 | nc termbin.com 9999)"

BW64 users may run this one-liner from the command line "as is" after removing $HERE/ because inxi is already included in BW64.
The script ends with a harmless warning since termbin.com adds a (non printable) NUL character to the URL. Ignore it.

williwaw
Posts: 1957
Joined: Tue Jul 14, 2020 11:24 pm
Has thanked: 172 times
Been thanked: 371 times

Re: Write script to run a command in (u)rxvt, and send the output to a text file?

Post by williwaw »

I started to use but I found this
https://www.malwarebytes.com/blog/detec ... ermbin-com

not sure if a particular url supplied by termbin is suspicious or what the issue is.
the warning at malwarebytes is undated

User avatar
mikewalsh
Moderator
Posts: 6163
Joined: Tue Dec 03, 2019 1:40 pm
Location: King's Lynn, UK
Has thanked: 795 times
Been thanked: 1983 times

Re: Write script to run a command in (u)rxvt, and send the output to a text file?

Post by mikewalsh »

@MochiMoppel :-

MochiMoppel wrote: Fri Oct 25, 2024 12:38 am

Instead of

Code: Select all

$HERE/inxi -Fxzzrc0 | nc termbin.com 9999 > /tmp/report.txt
/usr/lib/gtkdialog/box_splash -placement top -bg white -fg black -timeout 10 -text "  Copy URL BEFORE closing gxmessage window..! " &
sleep 0.25
gxmessage -bg yellow -fg black -name 'Termbin URL...' -center -file /tmp/report.txt
rm -f /tmp/report.txt

try

Code: Select all

gxmessage -bg yellow -fg black -name 'Termbin URL...' -center $'Copy URL BEFORE closing this  window..!\n'"$($HERE/inxi -Fxzzrc0 | nc termbin.com 9999)"

Ah, thanks for this, Mochi. That's much appreciated. I was trying to figure it out the other day, but my mind had just gone blank.....I simply wasn't thinking straight, and couldn't make stuff behave itself! :oops: :lol: Which is why I resorted to using what I could remember how to do..... :)

I've credited both you and Fred on the 'About' splash screen. (I may not have used Fred's code directly - like I have with yours - but it gave me ideas, and set me off on the right track..!)

Credit where credit is due.....and appreciated.

Mike. :D :thumbup:

User avatar
MochiMoppel
Posts: 1239
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 21 times
Been thanked: 440 times

Re: Write script to run a command in (u)rxvt, and send the output to a text file?

Post by MochiMoppel »

williwaw wrote: Fri Oct 25, 2024 1:42 am

not sure if a particular url supplied by termbin is suspicious or what the issue is

All URLs look suspicious :lol:

Try @mikewalsh 's first approach and send the output to a file:
echo hello | nc termbin.com 9999 > /tmp/url.txt
Now the file should contain the URL sent by termbin, right?

Open the file in Geany and have a look :o
If you have a Chinese font installed you might see a bunch of Chinese characters, if not you might see a bunch of boxes. If the random number supplied with the URL is larger than 4 digits Geany may refuse to open the file. If this doesn't look suspicious, what does? :?

williwaw
Posts: 1957
Joined: Tue Jul 14, 2020 11:24 pm
Has thanked: 172 times
Been thanked: 371 times

Re: Write script to run a command in (u)rxvt, and send the output to a text file?

Post by williwaw »

MochiMoppel wrote: Sat Oct 26, 2024 1:10 am

Try @mikewalsh 's first approach and send the output to a file:
echo hello | nc termbin.com 9999 > /tmp/url.txt
Now the file should contain the URL sent by termbin, right?

Open the file in Geany and have a look

I see what you mean, geany contains 瑨灴㩳⼯整浲楢⹮潣⽭㝭㈷

but if I go back to the terminal and
# cat /tmp/url.txt
bash returns
https://termbin.com/m772

so maybe a geany issue? because if I open /tmp/url.txt with leafpad I also see.......
https://termbin.com/m772

User avatar
MochiMoppel
Posts: 1239
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 21 times
Been thanked: 440 times

Re: Write script to run a command in (u)rxvt, and send the output to a text file?

Post by MochiMoppel »

williwaw wrote: Sat Oct 26, 2024 1:58 am

so maybe a geany issue?

Bingo!

User avatar
puppy_apprentice
Posts: 692
Joined: Tue Oct 06, 2020 8:43 pm
Location: land of bigos and schabowy ;)
Has thanked: 5 times
Been thanked: 115 times

Re: Write script to run a command in (u)rxvt, and send the output to a text file?

Post by puppy_apprentice »

Code: Select all

$HERE/inxi -Fxzzrc0 | nc termbin.com 9999 | xsel
/usr/lib/gtkdialog/box_splash -placement top -bg white -fg black -timeout 10 -text " The URL was copied to the clipboard... " &
sleep 0.25

https://www.ipqualityscore.com

Screenshot.png
Screenshot.png (69.2 KiB) Viewed 1015 times

https://www.ipqualityscore.com/domain-r ... ermbin.com

Doggy
Posts: 28
Joined: Thu Dec 02, 2021 7:00 pm
Been thanked: 7 times

Re: Write script to run a command in (u)rxvt, and send the output to a text file?

Post by Doggy »

The command you're using is sending the output of inxi to nc, but you need to capture the URL from nc instead. Try this:

Code: Select all

rxvt --hold -e sh -c "inxi -Fxzzr | nc termbin.com 9999 > /tmp/report.txt"

This way, you're running a shell command that pipes the output of inxi through nc and directly into your text file. Give it a shot and see if that works!

User avatar
fredx181
Posts: 3085
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 376 times
Been thanked: 1315 times
Contact:

Re: Write script to run a command in (u)rxvt, and send the output to a text file?

Post by fredx181 »

MochiMoppel wrote: Sat Oct 26, 2024 4:43 am
williwaw wrote: Sat Oct 26, 2024 1:58 am

so maybe a geany issue?

Bingo!

Well, not really a geany issue, I'd say, because the output url.txt is a "data" file.
Piping through "strings" fixes it, btw. :

Code: Select all

# echo hello | nc termbin.com 9999 > /tmp/url.txt
# file /tmp/url.txt
/tmp/url.txt: data
# echo hello | nc termbin.com 9999 | busybox strings > /tmp/url.txt
# file /tmp/url.txt
/tmp/url.txt: ASCII text

williwaw
Posts: 1957
Joined: Tue Jul 14, 2020 11:24 pm
Has thanked: 172 times
Been thanked: 371 times

Re: Write script to run a command in (u)rxvt, and send the output to a text file?

Post by williwaw »

fredx181 wrote: Sat Oct 26, 2024 11:22 am

Piping through "strings" fixes it, btw. :

Hi Fred,
I do not completely understand the difference between a data file and an ASCII text file, but if termbin.com returns a data file rather than an ASCII text file, is that a possible vector for a bad actor?

User avatar
puppy_apprentice
Posts: 692
Joined: Tue Oct 06, 2020 8:43 pm
Location: land of bigos and schabowy ;)
Has thanked: 5 times
Been thanked: 115 times

Re: Write script to run a command in (u)rxvt, and send the output to a text file?

Post by puppy_apprentice »

On Windows it shows as ASCII.

mobaxterm-on-win.png
mobaxterm-on-win.png (93.63 KiB) Viewed 775 times

Don't use $(nc termbin.com 9999 or command | nc termbin.com 9999) you can get command to execute if the bad guys take control of the service ;)

screenshott.png
screenshott.png (36.14 KiB) Viewed 775 times

https://mobaxterm.mobatek.net

CRLF Injection
https://owasp.org/www-community/vulnera ... _Injection

User avatar
norgo
Posts: 283
Joined: Mon Jul 13, 2020 6:39 pm
Location: Germany
Has thanked: 6 times
Been thanked: 111 times
Contact:

Re: Write script to run a command in (u)rxvt, and send the output to a text file?

Post by norgo »

mikewalsh wrote: Thu Oct 24, 2024 12:40 am

Am I right in thinking that anyone who wants to view your HTM file needs to have this installed.....or is it only used to actually generate the HTM file? In other words, the HTM file can be viewed anywhere, by anybody, and 'aha' won't be needed in order to view it?

Hello @mikewalsh
Aha is an Ansi Html Adapter (Converts ANSI escape sequences of a unix terminal to HTML code)
Aha is not needed to read the html file.
Furthermore is aha drastically faster in comparison to termbin.com

Code: Select all

time dmesg | aha > ~/dmesg.htm

real	0m0.018s
user	0m0.017s
sys	0m0.016s

Code: Select all

time dmesg | nc termbin.com 9999
https://termbin.com/06su

real	0m10.529s
user	0m0.018s
sys	0m0.006s

and simpler to use in my opinion
example:
dmesg --color=always | aha --black > ~/dmesg.htm

User avatar
puppy_apprentice
Posts: 692
Joined: Tue Oct 06, 2020 8:43 pm
Location: land of bigos and schabowy ;)
Has thanked: 5 times
Been thanked: 115 times

Re: Write script to run a command in (u)rxvt, and send the output to a text file?

Post by puppy_apprentice »

But with termbin.com, you can immediately share the output with other users. This is the functionality that Mike wanted i think.
You have to send the output from aha to the server yourself to show it to others.

User avatar
MochiMoppel
Posts: 1239
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 21 times
Been thanked: 440 times

Re: Write script to run a command in (u)rxvt, and send the output to a text file?

Post by MochiMoppel »

fredx181 wrote: Sat Oct 26, 2024 11:22 am

Well, not really a geany issue, I'd say, because the output url.txt is a "data" file.

@fredx181 @williwaw With "issue" I don't mean that it's a bug. On the contrary: Geany is completely correct here - if you agree with the way Geany tries to guess the encoding of a given file. When you look at Geany's status bar you can see that it considers the file to be encoded as UTF-16LE

The problem starts with the wrong encoding by termbin. Termbin adds 2 characters to the URL: A linefeed (0x0a) and a NUL character (0x00). This makes it a binary file and the mime type here is application/octet-stream. Geany is not supposed to read binary files and in most cases it refuses to do so with the message "The file does not look like a text file or the file encoding is not supported". But Geany supports UTF-16LE, and since UTF-16 reads a file in 2 byte chunks and the last 2 bytes are hex 0a and 00 and LE reverses the order the result is 000a, the correct encoding of a linefeed in UTF-16LE.
And indeed there is a linefeed in Geany's output. Now look at the first "block" character. In the block you can see the numbers 74 and 68, which means that this block is a placeholder for the Unicode character U+7468, a character that is part of the huge Unicode section "CJK Unified Ideographs" for Chinese/Japanese/Korean characters and which can't be properly displayed when a suitable Chinese font is not installed. Makes no sense? In UTF-16LE it does because termbin's URL starts with https://... Combining bytes of letter h (0x68) and letter t (0x74) and reversing the bytes results in 7468. Voilà, a Chinese character!

On the other hand Leafpad - seemingly - can read the file because it has a different policy. It just stops reading at the first NUL character it encounters and outputs whatever it was able to read up to this point.

Post Reply

Return to “Programming”