Let the speeds of the two trains be x m/sec and y m/sec respectively.
Then, length of the first train = 27x meters,
Length of the second train = 17y meters.
[because distance = speed × time]
27x+17y/x+y=23
=>27x+17y=23x+23y
=>4x=6y
=>x/y=6/4
So ratio of the speeds of train is 3:2