Dave-ee Jones Posted January 4, 2018 Share Posted January 4, 2018 Hoi! This is an issue I'm having some trouble with, and it's causing PopsWRT to constantly crash (I think..I'm running it from PuTTY to diagnose issues in the CLI instead of rebooting the PS constantly..). So I made a test script to narrow down the issue, but still can't work it out. So here's my issue: function test() { echo "Hey" } Output -> unexpected "(" on line 1 So I try and remove the brackets and this happens.. function test { echo "Hey" } Output -> unexpected "}" on line 3 You whot? Why's it breaking? I've 'chmodded' it and run it as a 'normal' script: chmod +x test.sh ./test.sh But it's still breaking. Any help would be appreciated! Quote Link to comment Share on other sites More sharing options...
Sebkinne Posted January 4, 2018 Share Posted January 4, 2018 Make sure you put the shebang at the start: #!/bin/bash Quote Link to comment Share on other sites More sharing options...
0phoi5 Posted January 4, 2018 Share Posted January 4, 2018 3 hours ago, Sebkinne said: Make sure you put the shebang at the start: #!/bin/bash Probably this. It seems like it's not recognising that you're running a BASH script. Quote Link to comment Share on other sites More sharing options...
Dave-ee Jones Posted January 4, 2018 Author Share Posted January 4, 2018 (edited) 13 hours ago, Sebkinne said: Make sure you put the shebang at the start: #!/bin/bash I thought that as well but I dismissed the idea because I ran it as a bash subshell once and it came up with errors for every empty line. Not to mention the start of that function again. I'll try it though. <insert bad pun here> Guess I forgot to write the whole shebang.. So that fixed the test.sh but not the payload.sh. The payload apparently doesn't exist. Staring right at it, bro. EDIT #998: So, I've found that it's Notepad++ causing the issue. It likes to put "^M" characters right before every new line, which means that every new line is a "^M" character combo. Classic Notepad++. It's a good program, they said. Never have an issue, they said. Best editor, they said. Mhm. Edited January 4, 2018 by Dave-ee Jones Quote Link to comment Share on other sites More sharing options...
Sebkinne Posted January 5, 2018 Share Posted January 5, 2018 Solution is simple: stop using windows to develop for Linux ;) Quote Link to comment Share on other sites More sharing options...
Dave-ee Jones Posted January 5, 2018 Author Share Posted January 5, 2018 (edited) 42 minutes ago, Sebkinne said: Solution is simple: stop using windows to develop for Linux ;) Your funny. What's even funnier is I think 90% of people (including Darren) are using Windows to build payloads for the BB, PS etc. It's a shame though. I tried writing it in Sublime Text and it did the same thing. Maybe standard Notepad is the way to go? :P EDIT: Using this command I was able to create a new file based on the old payload.sh which removed all the CTRL-M characters. tr -d $'\r' < payload.sh > payload_clean.sh I still cannot run the payload from the switch! It's flashing red, after a cyan and green! Edited January 5, 2018 by Dave-ee Jones Quote Link to comment Share on other sites More sharing options...
Foxtrot Posted January 5, 2018 Share Posted January 5, 2018 What is inside payload.sh? Quote Link to comment Share on other sites More sharing options...
Dave-ee Jones Posted January 5, 2018 Author Share Posted January 5, 2018 (edited) 9 minutes ago, Foxtrot said: What is inside payload.sh? Ohh, you know, the standard. A payload full of buggy goodness. It's got a load of functions. (I would PM you but your settings are set to 'Unsociable'...) Basically what happens is this: I can go into arming mode, SSH into the PS and type: ./payload.sh to launch the payload and it works like a charm. But, if I go to the switch position (position 3, the one on the left of arming mode - knowing that the positions go 1, 2, 3, arming) it boots up (green LED), starts the payload (cyan LED) and then errors (red LED forever). I've no idea why. I thought it might be something really silly, like me just putting it into the wrong switch position (very well could be), but I don't know. Could it be because of the directory (switch3) itself? I've deleted and remade it a few times, but if it's the same as the others (switch1, switch2, switch3) then it should be fine, right? With all the errors going on and the script working fine if called externally it appears to me that it has something to do with the PS not seeing it as a switch payload. It goes "what. what is switch3. what are you doing? are you stupid?". Edited January 5, 2018 by Dave-ee Jones Quote Link to comment Share on other sites More sharing options...
0phoi5 Posted January 5, 2018 Share Posted January 5, 2018 15 hours ago, Dave-ee Jones said: EDIT #998: So, I've found that it's Notepad++ causing the issue. It likes to put "^M" characters right before every new line, which means that every new line is a "^M" character combo. Classic Notepad++. It's a good program, they said. Never have an issue, they said. Best editor, they said. Mhm. Love it I do use Notepad++ myself to be honest, and it is brilliant. But yes, these things can happen! Make sure you're using the correct encoding in Notepad++, there's a drop down on the task bar at the top. I usually use UTF-8. Quote Link to comment Share on other sites More sharing options...
Dave-ee Jones Posted January 5, 2018 Author Share Posted January 5, 2018 Yeah. It works fine now as I run a clean.sh Everytime I put Pops on my PS. Anyway, it still won't run as a normal payload..what's the difference between them.. Quote Link to comment Share on other sites More sharing options...
PixL Posted January 5, 2018 Share Posted January 5, 2018 Kali and Mint Linux here.... bought a new laptop at the weekend and removed the windows installed hard drive without even booting it once... popped an SSD drive in and installed a better OS :) Quote Link to comment Share on other sites More sharing options...
Dave-ee Jones Posted January 6, 2018 Author Share Posted January 6, 2018 7 hours ago, PixL said: Kali and Mint Linux here.... bought a new laptop at the weekend and removed the windows installed hard drive without even booting it once... popped an SSD drive in and installed a better OS :) What in the world has that got to do with this topic.. Quote Link to comment Share on other sites More sharing options...
PixL Posted January 6, 2018 Share Posted January 6, 2018 My apologies it was probably a little off topic but there was some discussion above on using Windows to develop Linux payloads... i'll put the topic down now :) Quote Link to comment Share on other sites More sharing options...
digip Posted January 6, 2018 Share Posted January 6, 2018 On 1/4/2018 at 4:04 PM, Dave-ee Jones said: I thought that as well but I dismissed the idea because I ran it as a bash subshell once and it came up with errors for every empty line. Not to mention the start of that function again. I'll try it though. <insert bad pun here> Guess I forgot to write the whole shebang.. So that fixed the test.sh but not the payload.sh. The payload apparently doesn't exist. Staring right at it, bro. EDIT #998: So, I've found that it's Notepad++ causing the issue. It likes to put "^M" characters right before every new line, which means that every new line is a "^M" character combo. Classic Notepad++. It's a good program, they said. Never have an issue, they said. Best editor, they said. Mhm. Copy pasta also causes this in linux too, not just notepad++. When I copy code off web pages, and paste then save, I often get errors related to \r\n vs the \n that linux likes to use. You can open a python or bash script in nano, and it will actually highlight the issues, and python will even tell you about it in the error output of the terminal most of the time, then look in nano to see the highlighted blocks at the end of in middle of lines, to be removed. Sometimes it's also fancy quotes, something wordpress blogs are known for, vs a regular single quote, and can break code when you visually see or think it's a single quote in a text editor, when opened in a hex editor, you'll see it's not the proper character(s). Examples of what I mean. bad characters: e2 80 99 " ’ " should be single quote " ' " 27 e2 80 9d " ” " should be double-quote " 22 Quote Link to comment Share on other sites More sharing options...
Dave-ee Jones Posted January 7, 2018 Author Share Posted January 7, 2018 15 hours ago, digip said: Copy pasta also causes this in linux too, not just notepad++. When I copy code off web pages, and paste then save, I often get errors related to \r\n vs the \n that linux likes to use. You can open a python or bash script in nano, and it will actually highlight the issues, and python will even tell you about it in the error output of the terminal most of the time, then look in nano to see the highlighted blocks at the end of in middle of lines, to be removed. Sometimes it's also fancy quotes, something wordpress blogs are known for, vs a regular single quote, and can break code when you visually see or think it's a single quote in a text editor, when opened in a hex editor, you'll see it's not the proper character(s). Examples of what I mean. bad characters: e2 80 99 " ’ " should be single quote " ' " 27 e2 80 9d " ” " should be double-quote " 22 Yeh. I use nano to check if they have the broken characters. They're only on lines that have a line after them (it's an EOL character - CTRL-M) but Linux doesn't see it as CTRL-M even though it shows it as CTRL-M. It's actually \r, which makes sense because Linux sees the \n, but doesn't know what to do with the \r and treats it as part of the command on the line. So CTRL-M is actually \r\n. I'musing the tr function above to 'clean' the payload before running it. However, it shouldn't be affecting the run-via-switch otherwise it would've fixed it.. Quote Link to comment Share on other sites More sharing options...
digip Posted January 7, 2018 Share Posted January 7, 2018 (edited) The \r is a carriage return, and \n is new line(line feed). Linux generally treats \n as both in scripts, but if you ever download and open in windows, things like regular notepad, will make it all one line, which windows wants both the carriage return and new line. Notepad++ will treat \n like \r\n depending on how you have the settings, but you can also ctrl+h and set it to extended, to change \r\n to \n and then save it. If you click the icon to show all characters, you will see it adds a CR LF at the end of new lines. Also edit > EOL conversions, change to Unix, will remove CR LF and replace with LF ;) Edited January 7, 2018 by digip Quote Link to comment Share on other sites More sharing options...
Dave-ee Jones Posted January 7, 2018 Author Share Posted January 7, 2018 (edited) On 1/7/2018 at 2:58 PM, digip said: Also edit > EOL conversions, change to Unix, will remove CR LF and replace with LF ;) That's the first fix I tried - didn't work. Maybe I have to set it to that and then write the payload, as I set it to that after finishing the payload (obviously, after the problem occurred). On 1/7/2018 at 2:58 PM, digip said: Notepad++ will treat \n like \r\n depending on how you have the settings, but you can also ctrl+h and set it to extended, to change \r\n to \n and then save it. If you click the icon to show all characters, you will see it adds a CR LF at the end of new lines. I'll try that. Where's the icon? Found it. Anyway, this part's easy compared to troubleshooting why my payload is crashing on boot (red flashing LED after a cyan LED). It's fine if I run it via SSH. EDIT: That trick worked, and my clean.sh isn't needed anymore. Still have the switch problem though. Edited January 8, 2018 by Dave-ee Jones Quote Link to comment Share on other sites More sharing options...
Dave-ee Jones Posted January 9, 2018 Author Share Posted January 9, 2018 Fixed the switch problem. Probably something you want to look at Sebkinne, though it's not a huge issue - just a slight frustration that you wouldn't recognise unless you were at the bottom of your list of possibilities. I had a folder called "payloads" in my PopsWRT directory.. /root/payloads/switch3/payloads And it kept crashing because of that. Once I removed it (or renamed it) it booted PopsWRT fine. My guess is your using a symlink to get to a "payloads" directory to source the payloads from the switch folders? Not sure, could be something similar to that. Anyway, it's working fine now :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.