Ruby Net-SSH get on-login text and send data - ruby

when I run this command from my linux terminal:
ssh -p 12643 sudoku#ringzer0team.com
and enter the password, dg43zz6R0E, I get this message:
Linux ld64webdmz 3.2.0-4-amd64 #1 SMP Debian 3.2.82-1 x86_64
Last login: Fri Sep 22 09:19:02 2017 from 39.188.121.75
RingZer0 Team Online CTF
The sudoku challenge
+---+---+---+---+---+---+---+---+---+
| | 4 | 8 | | | 1 | 3 | 5 | 2 |
+---+---+---+---+---+---+---+---+---+
| 6 | 7 | | | 5 | | | 4 | |
+---+---+---+---+---+---+---+---+---+
| | | | | 4 | 8 | 6 | 7 | |
+---+---+---+---+---+---+---+---+---+
| 4 | | | | 1 | 3 | 5 | 2 | 9 |
+---+---+---+---+---+---+---+---+---+
| | | 3 | 5 | 2 | | | | 6 |
+---+---+---+---+---+---+---+---+---+
| | | 9 | | | 6 | | 1 | |
+---+---+---+---+---+---+---+---+---+
| | | | | | | | | 4 |
+---+---+---+---+---+---+---+---+---+
| | | | 2 | | | | | |
+---+---+---+---+---+---+---+---+---+
| 2 | | | | | | 1 | | |
+---+---+---+---+---+---+---+---+---+
Solve this sudoku in less than 10 seconds and you'll get the flag.
Submit all the sudoku table using this format from left to right 1,2,3,4,5,6,7,8,9,2,3,4,5,6,7,8,9,1...
Solution:
Using Net-SSH from Ruby, how can I get that on-login message and send a response?
This is what I have:
#!/usr/bin/ruby
require'net/ssh';
Net::SSH.start('ringzer0team.com', 'sudoku', :password => 'dg43zz6R0E', :port => 12643) do|ssh|
# read that on_login text, solve and send output
p ssh.exec!(((1..9).to_a*9).join(',')+"\n"); # trying to send data
end
It does not terminate (does not get past the call to exec!).
I'm just asking about how to interact with the session (get and send data), not on how to solve the sudoku.

Related

How to compare two circuits based on their utilization

I have some hardware IPs that I need to synthesize. And the IP contains several generic parameters I can play with. Each combination of parameters gives me a different utilization report after synthesis and implementation.
So for example for two different configurations Design_1 and Design_2, I get the following in Vivado 2018.1. The 3rd line is the ratio of the values of Design_2 devided by values of Design_1.
So as you can see in this simple example, Design_2 has less Slice LUTs but slightly more F7 Muxes.
My question is how to conclude about the cost of each one? Should I privilege Slice LUTs or Registers ...etc?
+----------+-------------------+-----------------+------------------+----------+-------------------+-------------------+---------------+---------------------+----------------+------+------------+--------------+-------------+------------+----------+---------+------------+---------+---------------------------+-------------------------+-----------------------------+--------+--------+----------+---------+------------+-----------+---------+--------+---------+---------+-----------+----------+-----------+-------------+---------+----------+-----------+---------+
| Name | Slice LUTs | Slice Registers | F7 Muxes | F8 Muxes | Slice | LUT as Logic | LUT as Memory | LUT Flip Flop Pairs | Block RAM Tile | DSPs | Bonded IOB | Bonded IPADs | PHY_CONTROL | PHASER_REF | OUT_FIFO | IN_FIFO | IDELAYCTRL | IBUFDS | PHASER_OUT/PHASER_OUT_PHY | PHASER_IN/PHASER_IN_PHY | IDELAYE2/IDELAYE2_FINEDELAY | ILOGIC | OLOGIC | BUFGCTRL | BUFIO | MMCME2_ADV | PLLE2_ADV | BUFMRCE | BUFHCE | BUFR | BSCANE2 | CAPTUREE2 | DNA_PORT | EFUSE_USR | FRAME_ECCE2 | ICAPE2 | PCIE_2_1 | STARTUPE2 | XADC |
+----------+-------------------+-----------------+------------------+----------+-------------------+-------------------+---------------+---------------------+----------------+------+------------+--------------+-------------+------------+----------+---------+------------+---------+---------------------------+-------------------------+-----------------------------+--------+--------+----------+---------+------------+-----------+---------+--------+---------+---------+-----------+----------+-----------+-------------+---------+----------+-----------+---------+
| Design_1 | 34124 | 16913 | 1453 | 91 | 10272 | 31538 | 2586 | 9020 | 37 | 11 | 125 | 0 | 1 | 1 | 4 | 2 | 1 | 0 | 4 | 2 | 16 | 16 | 46 | 10 | 0 | 2 | 2 | 0 | 2 | 0 | 4 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| Design_2 | 34097 | 16913 | 1550 | 91 | 10189 | 31511 | 2586 | 9021 | 37 | 11 | 125 | 0 | 1 | 1 | 4 | 2 | 1 | 0 | 4 | 2 | 16 | 16 | 46 | 10 | 0 | 2 | 2 | 0 | 2 | 0 | 4 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| -------- | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| (2)/(1) | 0.999208768022506 | 1 | 1.06675843083276 | 1 | 0.991919781931464 | 0.999143889910584 | 1 | 1.00011086474501 | 1 | 1 | 1 | #DIV/0! | 1 | 1 | 1 | 1 | 1 | #DIV/0! | 1 | 1 | 1 | 1 | 1 | 1 | #DIV/0! | 1 | 1 | #DIV/0! | 1 | #DIV/0! | 1 | #DIV/0! | #DIV/0! | #DIV/0! | #DIV/0! | #DIV/0! | #DIV/0! | #DIV/0! | #DIV/0! |
+----------+-------------------+-----------------+------------------+----------+-------------------+-------------------+---------------+---------------------+----------------+------+------------+--------------+-------------+------------+----------+---------+------------+---------+---------------------------+-------------------------+-----------------------------+--------+--------+----------+---------+------------+-----------+---------+--------+---------+---------+-----------+----------+-----------+-------------+---------+----------+-----------+---------+
It's depending on your needs, LUTs and F7 Muxes are differents physical cells in your FPGA. So even if you don't use its, its will be there.
If you have one ressource more critical than the other, you should try to minimize the utilisation of the critical ressource to simplify the place and route.
If you have nothing critical, I think the better is to use F7 Muxes first because Slice LUTs are more flexible for the rest of your design.

Pivot Table in Hive and Create Multiple Columns for Unique Combinations

I want to pivot the following table
| ID | Code | date | qty |
| 1 | A | 1/1/19 | 11 |
| 1 | A | 2/1/19 | 12 |
| 2 | B | 1/1/19 | 13 |
| 2 | B | 2/1/19 | 14 |
| 3 | C | 1/1/19 | 15 |
| 3 | C | 3/1/19 | 16 |
into
| ID | Code | mth_1(1/1/19) | mth_2(2/1/19) | mth_3(3/1/19) |
| 1 | A | 11 | 12 | 0 |
| 2 | B | 13 | 14 | 0 |
| 3 | C | 15 | 0 | 16 |
I am new to hive, i am not sure how to implement it.
NOTE: I don't want to do mapping because my month values change over time.

Determinate unique values from oracle join?

I need a way to avoid duplicate values from oracle join, I have this scenario.
The first table contain general information about a person.
+-----------+-------+-------------+
| ID | Name | Birtday_date|
+-----------+-------+-------------+
| 1 | Byron | 12/10/1998 |
| 2 | Peter | 01/11/1973 |
| 4 | Jose | 05/02/2008 |
+-----------+-------+-------------+
The second table contain information about a telephone of the people in the first table.
+-------+----------+----------+----------+
| ID |ID_Person |CELL_TYPE | NUMBER |
+-------+- --------+----------+----------+
| 1221 | 1 | 3 | 099141021|
| 2221 | 1 | 2 | 099091925|
| 3222 | 1 | 1 | 098041013|
| 4321 | 2 | 1 | 088043153|
| 4561 | 2 | 2 | 090044313|
| 5678 | 4 | 1 | 092049013|
| 8990 | 4 | 2 | 098090233|
+----- -+----------+----------+----------+
The Third table contain information about a email of the people in the first table.
+------+----------+----------+---------------+
| ID |ID_Person |EMAIL_TYPE| Email |
+------+- --------+----------+---------------+
| 221 | 1 | 1 |jdoe#aol.com |
| 222 | 1 | 2 |jdoe1#aol.com |
| 421 | 2 | 1 |xx12#yahoo.com |
| 451 | 2 | 2 |dsdsa#gmail.com|
| 578 | 4 | 1 |sasaw1#sdas.com|
| 899 | 4 | 2 |cvcvsd#wew.es |
| 899 | 4 | 2 |cvsd#www.es |
+------+----------+----------+---------------+
I was able to produce a result like this, you can check in this link http://sqlfiddle.com/#!4/8e326/1
+-----+-------+-------------+----------+----------+----------+----------------+
| ID | Name | Birtday_date| CELL_TYPE| NUMBER |EMAIL_TYPE|EMAIL|
+-----+-------+-------------+----------+----------+----------+----------------+
| 1 | Byron | 12/10/1998 | 3 | 099141021|1 |jdoe#aol.com |
| 1 | Byron | 12/10/1998 | 2 | 099091925|2 |jdoe1#aol.com |
| 1 | Byron | 12/10/1998 | 1 | 099091925| | |
| 2 | Peter | 01/11/1973 | 1 | 088043153|1 |xx12#yahoo.com |
| 2 | Peter | 01/11/1973 | 2 | 090044313|2 |dsdsa#gmail.com |
| 4 | Jose | 05/02/2008 | 1 | 092049013|1 |sasaw1#sdas.com |
| 4 | Jose | 05/02/2008 | 2 | 098090233|2 |cvcvsd#wew.es |
+-----+-------+-------------+----------+----------+----------+----------------+
If you check the data in table Email for user with ID_Person = 4 only present two of the three emails that have, the problem for this case is the person have more emails that cellphone numbers and only will present the same number of the cellphone numbers.
The result i expected is something like this.
+-----+-------+-------------+----------+----------+----------+----------------+
| ID | Name | Birtday_date| CELL_TYPE| NUMBER |EMAIL_TYPE|EMAIL|
+-----+-------+-------------+----------+----------+----------+----------------+
| 1 | Byron | 12/10/1998 | 3 | 099141021|1 |jdoe#aol.com |
| 1 | Byron | 12/10/1998 | 2 | 099091925|2 |jdoe1#aol.com |
| 1 | Byron | 12/10/1998 | 1 | 099091925| | |
| 2 | Peter | 01/11/1973 | 1 | 088043153|1 |xx12#yahoo.com |
| 2 | Peter | 01/11/1973 | 2 | 090044313|2 |dsdsa#gmail.com |
| 4 | Jose | 05/02/2008 | 1 | 092049013|1 |sasaw1#sdas.com |
| 4 | Jose | 05/02/2008 | 2 | 098090233|2 |cvcvsd#wew.es |
| 4 | Jose | 05/02/2008 | | |2 |cvsd#www.es |
+-----+-------+-------------+----------+----------+----------+----------------+
This is the way that i need to present the data.
I could not understand why your query was so complex, thus, added the simple full outer join and it seems to be working:
select distinct p.id, p.name,
case when Lag(CELL) over(partition by p.id order by p.id,pe.id) = CELL then null else cell_type end as cell_type,
case when Lag(CELL) over(partition by p.id order by p.id,pe.id) = CELL then null else CELL end as CELL,
EMAIL_TYPE as EMAIL_TYPE, EMAIL as EMAIL
from person p full outer join phones pe on p.id = pe.id
full outer join emails e
on p.id = e.id and pe.cell_type = e.email_type;

Persistent Command Line Display

I am writing a little Sudoku solving app in Ruby that just outputs to the terminal. For example:
ruboku $ ruby grid.rb
+---+---+---+---+---+---+---+---+---+
| 2 | 8 | 5 | | 3 | 1 | 7 | 6 | 9 |
+---+---+---+---+---+---+---+---+---+
| 5 | | 4 | 8 | 7 | 2 | 1 | 9 | 3 |
+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+
Is there a way to keep this as a persistent display such that when there is new information to show it doesn't print a new line, but updates the grid that is already displaying?
I've seen some tools such as ngrok who do this.
Thanks for your time,
Tom
Depending on your needs, erasing the screen and creating the grid again could be good enough :
def show_grid
line = '+---+---+---+---+---+---+---+---+---+'
puts line
9.times do
row = (1..9).map { rand(9) + 1 }
puts '| ' + row.join(' | ') + ' |'
puts line
end
end
def clear_screen
system('clear') || system('cls')
end
loop do
clear_screen
show_grid
sleep 1
end
It outputs
+---+---+---+---+---+---+---+---+---+
| 1 | 2 | 7 | 3 | 4 | 9 | 8 | 6 | 5 |
+---+---+---+---+---+---+---+---+---+
| 1 | 8 | 1 | 7 | 6 | 2 | 2 | 1 | 3 |
+---+---+---+---+---+---+---+---+---+
| 2 | 2 | 1 | 2 | 2 | 8 | 2 | 3 | 6 |
+---+---+---+---+---+---+---+---+---+
| 5 | 3 | 6 | 1 | 5 | 3 | 2 | 7 | 9 |
+---+---+---+---+---+---+---+---+---+
| 9 | 7 | 7 | 4 | 7 | 2 | 2 | 9 | 1 |
+---+---+---+---+---+---+---+---+---+
| 5 | 9 | 1 | 9 | 3 | 7 | 8 | 3 | 1 |
+---+---+---+---+---+---+---+---+---+
| 8 | 5 | 4 | 7 | 3 | 2 | 2 | 5 | 3 |
+---+---+---+---+---+---+---+---+---+
| 4 | 7 | 1 | 1 | 4 | 8 | 4 | 1 | 1 |
+---+---+---+---+---+---+---+---+---+
| 1 | 1 | 8 | 4 | 2 | 4 | 8 | 3 | 8 |
+---+---+---+---+---+---+---+---+---+
then
+---+---+---+---+---+---+---+---+---+
| 6 | 4 | 4 | 3 | 5 | 5 | 8 | 9 | 1 |
+---+---+---+---+---+---+---+---+---+
| 7 | 7 | 7 | 3 | 3 | 2 | 8 | 7 | 6 |
+---+---+---+---+---+---+---+---+---+
| 6 | 2 | 2 | 1 | 4 | 7 | 1 | 1 | 9 |
+---+---+---+---+---+---+---+---+---+
| 3 | 8 | 7 | 7 | 7 | 9 | 7 | 4 | 4 |
+---+---+---+---+---+---+---+---+---+
| 4 | 1 | 2 | 8 | 6 | 7 | 1 | 9 | 3 |
+---+---+---+---+---+---+---+---+---+
| 6 | 7 | 7 | 5 | 1 | 7 | 6 | 7 | 4 |
+---+---+---+---+---+---+---+---+---+
| 8 | 2 | 3 | 5 | 3 | 5 | 4 | 7 | 2 |
+---+---+---+---+---+---+---+---+---+
| 5 | 9 | 3 | 2 | 4 | 2 | 9 | 6 | 3 |
+---+---+---+---+---+---+---+---+---+
| 1 | 7 | 8 | 9 | 4 | 3 | 4 | 1 | 5 |
+---+---+---+---+---+---+---+---+---+
then...
It should work on Windows/Linux/MacOs.
For anything more complex, you'll need an ncurses gem.
So the question is marked as answered I thought I would write up the advice given to me in the comments.
It looks like the ncurses ruby gem and vedeu offer the functionality that I need. Another alternative would be to clear the scren and reprint the output.

mysql table unaligned in console output when using UTF8

I like to use mysql client. But when using UTF-8, the tables on the console are unaligned:
> set names utf8;
> [some query]
+--------+---------+---------------------------------+-----------------------------+----------+---------+-----------+-------+---------+-----------+
| RuleId | TaxonId | Note | NoteSci | MinCount | DayFrom | MonthFrom | DayTo | MonthTo | ExtraNote |
+--------+---------+---------------------------------+-----------------------------+----------+---------+-----------+-------+---------+-----------+
| 722 | 10090 | sedmihlásek malý | Hippolais caligata | 1 | 1 | 1 | 31 | 12 | NULL |
| 727 | 10059 | Anseranas semipalmata | husovec strakatý | 1 | 1 | 1 | 31 | 12 | NULL |
| 728 | 10062 | Cygnus atratus | labuť černá | 1 | 1 | 1 | 31 | 12 | NULL |
| 729 | 10094 | Anser cygnoides | husa labutí | 1 | 1 | 1 | 31 | 12 | NULL |
| 730 | 10063 | Tadorna cana | husice šedohlavá | 1 | 1 | 1 | 31 | 12 | NULL |
| 731 | 10031 | Cairina moschata f. domestica | pižmovka domácí | 20 | 1 | 1 | 31 | 12 | NULL |
| 732 | 10088 | Cairina scutulata | pižmovka bělokřídlá | 1 | 1 | 1 | 31 | 12 | NULL |
| 733 | 10087 | Anas sibilatrix | hvízdák chilský | 1 | 1 | 1 | 31 | 12 | NULL |
| 734 | 10077 | Anas platyrhynchos f. domestica | kachna domácí | 1000 | 1 | 1 | 31 | 12 | NULL |
| 735 | 10086 | Anas hottentota | čírka hottentotská | 1 | 1 | 1 | 31 | 12 | NULL |
|
This is apparently because mysql client will compute the widths of the columns using string length which doesn't take UTF-8 characters into account - so then there is exactly one space missing for each accented character (because these actually take two bytes).
Do you know possible workaround for this problem?
Run your mysql client with charset option:
mysql -uUSER -p DATABASE --default-character-set=utf8
(USER and DATABASE should be replaced with actual credentials data)

Resources